Skip to content

Commit

Permalink
[cmd/mdatagen] Allow passing SDK metric options to SetupTelemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Jan 22, 2025
1 parent 45a8024 commit 8e93263
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 18 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_setup-telemetry-options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow passing OTel Metric SDK options to the generated `SetupTelemetry` function.

# One or more tracking issues or pull requests related to the change
issues: [12160]

# (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:

# 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: [api]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions cmd/mdatagen/internal/templates/telemetrytest.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,30 @@ type Telemetry struct {
traceProvider *sdktrace.TracerProvider
}

func SetupTelemetry() Telemetry {
type SetupTelemetryOption struct {
sdkMetricOption *sdkmetric.Option
}

func WithSDKMetricOption(option sdkmetric.Option) SetupTelemetryOption {
return SetupTelemetryOption{sdkMetricOption: &option}
}

func SetupTelemetry(options ...SetupTelemetryOption) Telemetry {
reader := sdkmetric.NewManualReader()
spanRecorder := new(tracetest.SpanRecorder)

sdkMetricOptions := []sdkmetric.Option{sdkmetric.WithReader(reader)}
for _, option := range options {
if option.sdkMetricOption != nil {
sdkMetricOptions = append(sdkMetricOptions, *option.sdkMetricOption)
}
}

return Telemetry{
Reader: reader,
SpanRecorder: spanRecorder,

meterProvider: sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)),
meterProvider: sdkmetric.NewMeterProvider(sdkMetricOptions...),
traceProvider: sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(spanRecorder)),
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions service/internal/metadatatest/generated_telemetrytest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e93263

Please sign in to comment.