Add service.name/version to OTLP log resource#5536
Open
ramonsmits wants to merge 1 commit into
Open
Conversation
a61e0b6 to
560fba3
Compare
The OTLP log exporter was registered with a bare AddOtlpExporter() and no OpenTelemetry resource, so exported log records had no service identity and showed up as "unknown_service" in the backend. LoggerUtil.Initialize(serviceName, serviceVersion) is now called once at process startup (in each instance's Program.cs, before any logger is created) and builds a single OpenTelemetry resource — service.name = instance name, service.version = instance version, plus an auto-generated service.instance.id. Both the host logging pipeline and the static bootstrap loggers (CreateStaticLogger) share that resource, so every exported record — including early startup diagnostics — is attributed to the instance. service.name matches the value used by the Audit metrics resource, so logs and metrics correlate. The resource still uses ResourceBuilder.CreateDefault(), so operators can enrich it with deployment attributes via OTEL_SERVICE_NAME / OTEL_RESOURCE_ATTRIBUTES.
560fba3 to
76bdd61
Compare
ramonsmits
commented
Jun 17, 2026
| // Establish the telemetry identity once, before any logger is created, so every logger — including the | ||
| // static bootstrap loggers — attributes exported OTLP logs to this instance. Mirrors the InstanceName | ||
| // resolution in Settings (InternalQueueName is the legacy fallback for the instance name). | ||
| var instanceName = SettingsReader.Read(Settings.SettingsRootNamespace, "InstanceName", |
Member
Author
There was a problem hiding this comment.
@WilliamBZA @dvdstelt this is really needed to ensure OTel related attributes are set.
The version could be extracted in the LoggerUtil.Initialize as that version is the same for all SC assemblies in the build.
However, the name is not, unfortnately although very similar for all 3 instances SettingsReader can be used in LoggerUtil but not Settings which is instance specific.
Any refactorings you can think of to maybe this a bit less fugly?
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 noOpenTelemetry resource, so exported logs arrived as
unknown_serviceand couldn't beattributed or correlated. This PR gives every exported log record a service identity for
all three instances (ServiceControl, Audit, Monitoring), matching the
service.namealready used by the Audit metrics resource so logs and metrics correlate.
What changed
LoggerUtil.Initialize(serviceName, serviceVersion)is called once at startup (in eachProgram.cs, before any logger is created) and builds a single OpenTelemetry resourceshared by both the host logging pipeline and the static bootstrap loggers — so all
exported records are attributed, including early startup diagnostics.
service.nameservice.versionservice.instance.idOperator configuration
Enable OTLP logging by adding
OtlptoLoggingProviders; the endpoint comes from thestandard
OTEL_EXPORTER_OTLP_ENDPOINT. The resource usesResourceBuilder.CreateDefault(),so operators can tag a deployment via
OTEL_RESOURCE_ATTRIBUTES(these ride on every record):Code-set
service.*win; extra attributes are merged in. For a stable id across restarts,set
service.instance.idexplicitly here.Testing
The collector prints each record's
Resource attributeswithservice.name = <instance name>.