Add service.name/version to OTLP log resource#5536
Draft
ramonsmits wants to merge 1 commit into
Draft
Conversation
The OTLP log exporter was registered with a bare AddOtlpExporter(), so exported logs arrived with no resource and showed up as "unknown_service" in the backend. Attach service.name, service.version and an auto-generated service.instance.id to the OTLP log resource for all three instances (ServiceControl, Audit, Monitoring), sourced from the instance name and assembly version — matching the resource already configured on the Audit metrics path so logs and metrics correlate by service. The resource still uses ResourceBuilder.CreateDefault(), so operators can enrich it with deployment-specific attributes via OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES.
a61e0b6 to
560fba3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OTLP log exporter was registered with a bare
AddOtlpExporter()and no OpenTelemetry resource, so exported log records arrived at the collector/backend with no service identity and showed up asunknown_service:<process>. This makes logs from a ServiceControl instance impossible to attribute or correlate.This PR attaches a proper resource to the OTLP log exporter for all three instances (ServiceControl, Audit, Monitoring), mirroring the resource already configured on the Audit metrics path so logs and metrics correlate by the same
service.name.What changed
LoggerUtilnow sets an OpenTelemetry resource on the OTLP logging provider viaResourceBuilder.CreateDefault().AddService(...), guarded so non-host paths (static loggers, tests) keep their current behavior when no service name is set.ServiceControl,ServiceControl.Audit,ServiceControl.Monitoring).Resulting resource attributes on exported logs
service.nameservice.versionservice.instance.idOperator configuration
The resource is built with
ResourceBuilder.CreateDefault(), which means the standard OpenTelemetry environment variables are honored. Operators can enrich the resource attached to every exported log record (and metric) without any code or config-file changes — useful for identifying a specific deployment in the telemetry backend.OTEL_SERVICE_NAME— setsservice.name.OTEL_RESOURCE_ATTRIBUTES— a comma-separated list ofkey=valuepairs added to the resource. Use this to tag a deployment with anything your backend should be able to filter and group on:These attributes ride on all telemetry from the instance, so they can be used to slice logs (and metrics) by environment, region, cluster, tenant, release, etc.
Behavior
service.name= instance name,service.version= assembly version, autoservice.instance.id) — so logs are attributable out of the box.service.name,service.version,service.instance.id) take precedence over the same keys supplied via the environment variables. Any additional attributes inOTEL_RESOURCE_ATTRIBUTES(e.g.deployment.environment,service.namespace, custom*keys) are merged in and exported.service.instance.idis auto-generated as a new GUID on every process start. For a stable per-deployment identity across restarts, set it explicitly viaOTEL_RESOURCE_ATTRIBUTES=service.instance.id=<stable-value>(e.g. pod name / hostname).OTLP log export is enabled, as before, by including
Otlpin theLoggingProviderssetting; the OTLP endpoint is configured via the standardOTEL_EXPORTER_OTLP_ENDPOINT(and relatedOTEL_EXPORTER_OTLP_*) environment variables.