diff --git a/.chloggen/fix-clickhouse-json-exporter-factory.yaml b/.chloggen/fix-clickhouse-json-exporter-factory.yaml new file mode 100644 index 0000000000000..de852b766cbbf --- /dev/null +++ b/.chloggen/fix-clickhouse-json-exporter-factory.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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. receiver/filelog) +component: exporter/clickhouse + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix a bug in the exporter factory resulting in a nil dereference panic when the clickhouse.json feature gate is enabled + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [43733] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/exporter/clickhouseexporter/exporter_logs_json.go b/exporter/clickhouseexporter/exporter_logs_json.go index 3c9883235ca76..5f14d57545d06 100644 --- a/exporter/clickhouseexporter/exporter_logs_json.go +++ b/exporter/clickhouseexporter/exporter_logs_json.go @@ -18,6 +18,13 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/sqltemplates" ) +// anyLogsExporter is an interface that satisfies both the default map logsExporter and the logsJSONExporter +type anyLogsExporter interface { + start(context.Context, component.Host) error + shutdown(context.Context) error + pushLogsData(context.Context, plog.Logs) error +} + type logsJSONExporter struct { cfg *Config logger *zap.Logger diff --git a/exporter/clickhouseexporter/exporter_traces_json.go b/exporter/clickhouseexporter/exporter_traces_json.go index fc317f808868d..43fe5b628c16f 100644 --- a/exporter/clickhouseexporter/exporter_traces_json.go +++ b/exporter/clickhouseexporter/exporter_traces_json.go @@ -18,6 +18,13 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal/sqltemplates" ) +// anyTracesExporter is an interface that satisfies both the default map tracesExporter and the tracesJSONExporter +type anyTracesExporter interface { + start(context.Context, component.Host) error + shutdown(context.Context) error + pushTraceData(ctx context.Context, td ptrace.Traces) error +} + type tracesJSONExporter struct { cfg *Config logger *zap.Logger diff --git a/exporter/clickhouseexporter/factory.go b/exporter/clickhouseexporter/factory.go index 65b69fba2f896..a8122613c3bd6 100644 --- a/exporter/clickhouseexporter/factory.go +++ b/exporter/clickhouseexporter/factory.go @@ -37,11 +37,11 @@ func createLogsExporter( c := cfg.(*Config) c.collectorVersion = set.BuildInfo.Version - exp := newLogsExporter(set.Logger, c) - startOpt := exporterhelper.WithStart(exp.start) + var exp anyLogsExporter if featureGateJSON.IsEnabled() { - exp := newLogsJSONExporter(set.Logger, c) - startOpt = exporterhelper.WithStart(exp.start) + exp = newLogsJSONExporter(set.Logger, c) + } else { + exp = newLogsExporter(set.Logger, c) } return exporterhelper.NewLogs( @@ -49,7 +49,7 @@ func createLogsExporter( set, cfg, exp.pushLogsData, - startOpt, + exporterhelper.WithStart(exp.start), exporterhelper.WithShutdown(exp.shutdown), exporterhelper.WithTimeout(c.TimeoutSettings), exporterhelper.WithQueue(c.QueueSettings), @@ -65,11 +65,11 @@ func createTracesExporter( c := cfg.(*Config) c.collectorVersion = set.BuildInfo.Version - exp := newTracesExporter(set.Logger, c) - startOpt := exporterhelper.WithStart(exp.start) + var exp anyTracesExporter if featureGateJSON.IsEnabled() { - exp := newTracesJSONExporter(set.Logger, c) - startOpt = exporterhelper.WithStart(exp.start) + exp = newTracesJSONExporter(set.Logger, c) + } else { + exp = newTracesExporter(set.Logger, c) } return exporterhelper.NewTraces( @@ -77,7 +77,7 @@ func createTracesExporter( set, cfg, exp.pushTraceData, - startOpt, + exporterhelper.WithStart(exp.start), exporterhelper.WithShutdown(exp.shutdown), exporterhelper.WithTimeout(c.TimeoutSettings), exporterhelper.WithQueue(c.QueueSettings),