New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read resource settings from environment variables #8
Conversation
This brings makes the OTel resource effectively the same as resource.Default() with the addition of explicitly setting the service.name
otel.go
Outdated
@@ -124,7 +124,7 @@ func OpenTelemetryRunE(flagPrefix string, prerunLevel zerolog.Level) CobraRunFun | |||
} | |||
|
|||
func initOtelTracer(exporter trace.SpanExporter, serviceName string, propagators []string) error { | |||
res, _ := resource.New(context.Background(), resource.WithAttributes(semconv.ServiceNameKey.String(serviceName))) | |||
res, _ := setResource(serviceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does return an error. Any reason why we shouldn't propagate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved in b9a185a
otel.go
Outdated
@@ -124,7 +124,11 @@ func OpenTelemetryRunE(flagPrefix string, prerunLevel zerolog.Level) CobraRunFun | |||
} | |||
|
|||
func initOtelTracer(exporter trace.SpanExporter, serviceName string, propagators []string) error { | |||
res, _ := resource.New(context.Background(), resource.WithAttributes(semconv.ServiceNameKey.String(serviceName))) | |||
res, err := setResource(serviceName) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nitpick: drop this new line
Settings such as
OTEL_RESOURCE_ATTRIBUTES
were not being read in from environment variables. Having this available is important for some automated environments whereOTEL_RESOURCE_ATTRIBUTES
is auto-generated from deployment tooling.Note that setting
service.name
inOTEL_RESOURCE_ATTRIBUTES
or viaOTEL_SERVICE_NAME
will still be a no-op because there is a default value set from the command line flags.This also bumps the https://github.com/open-telemetry/opentelemetry-go libraries to the latest stable release. This was required to get it to work with our LightStep environment, although I'm not entirely sure what in the changelog was breaking.
Finally, the https://pkg.go.dev/go.opentelemetry.io/otel/sdk@v1.6.3/resource#WithTelemetrySDK detector was added to inject version information about the OpenTelemetry SDK libraries into span attributes. This is to aid administration of observability services.