Skip to content

Commit

Permalink
[elasticexporter] Fix nil panic when setting custom headers (open-tel…
Browse files Browse the repository at this point in the history
…emetry#16017)

* (bugfix)(elasticexporter) Fix nil panic when setting custom headers

* Added changelog

* Update .chloggen/elasticexporter-fix-custom-header.yaml

Co-authored-by: Pablo Baeyens <[email protected]>

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
canhnt and mx-psi committed Nov 2, 2022
1 parent 92f9ced commit fc8b9e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/elasticexporter-fix-custom-header.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: elasticsearchexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixed nil panic error when setting custom headers in elasticsearch exporter

# One or more tracking issues related to the change
issues: [16017]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion exporter/elasticsearchexporter/elasticsearch_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func newElasticsearchClient(logger *zap.Logger, config *Config) (*esClientCurren

transport := newTransport(config, tlsCfg)

var headers http.Header
headers := make(http.Header)
for k, v := range config.Headers {
headers.Add(k, v)
}
Expand Down
9 changes: 9 additions & 0 deletions exporter/elasticsearchexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func TestExporter_New(t *testing.T) {
}),
want: failWithMessage("Addresses and CloudID are set"),
},
"create with custom request header": {
config: withDefaultConfig(func(cfg *Config) {
cfg.Endpoints = []string{"test:9200"}
cfg.Headers = map[string]string{
"foo": "bah",
}
}),
want: success,
},
}

for name, test := range tests {
Expand Down

0 comments on commit fc8b9e6

Please sign in to comment.