Skip to content

Add service.name/version to OTLP log resource#5536

Draft
ramonsmits wants to merge 1 commit into
authfrom
otel-service-names
Draft

Add service.name/version to OTLP log resource#5536
ramonsmits wants to merge 1 commit into
authfrom
otel-service-names

Conversation

@ramonsmits

@ramonsmits ramonsmits commented Jun 15, 2026

Copy link
Copy Markdown
Member

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 as unknown_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

  • LoggerUtil now sets an OpenTelemetry resource on the OTLP logging provider via ResourceBuilder.CreateDefault().AddService(...), guarded so non-host paths (static loggers, tests) keep their current behavior when no service name is set.
  • Each instance populates the service identity at startup from its configured instance name and assembly version (ServiceControl, ServiceControl.Audit, ServiceControl.Monitoring).

Resulting resource attributes on exported logs

Attribute Value
service.name the instance name (same value the metrics resource uses)
service.version the instance assembly version
service.instance.id auto-generated GUID per process start

Operator 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 — sets service.name.
  • OTEL_RESOURCE_ATTRIBUTES — a comma-separated list of key=value pairs added to the resource. Use this to tag a deployment with anything your backend should be able to filter and group on:
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.namespace=acme-payments,service.instance.id=sc-prod-euw1-node3,acme.region=eu-west-1,acme.cluster=k8s-prod-2

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

  • With nothing set, the instance supplies sensible defaults (service.name = instance name, service.version = assembly version, auto service.instance.id) — so logs are attributable out of the box.
  • The values ServiceControl sets in code (service.name, service.version, service.instance.id) take precedence over the same keys supplied via the environment variables. Any additional attributes in OTEL_RESOURCE_ATTRIBUTES (e.g. deployment.environment, service.namespace, custom * keys) are merged in and exported.
  • Tip: service.instance.id is auto-generated as a new GUID on every process start. For a stable per-deployment identity across restarts, set it explicitly via OTEL_RESOURCE_ATTRIBUTES=service.instance.id=<stable-value> (e.g. pod name / hostname).

OTLP log export is enabled, as before, by including Otlp in the LoggingProviders setting; the OTLP endpoint is configured via the standard OTEL_EXPORTER_OTLP_ENDPOINT (and related OTEL_EXPORTER_OTLP_*) environment variables.

@ramonsmits ramonsmits changed the title ✨ Add service.name/version to OTLP log resource Add service.name/version to OTLP log resource Jun 15, 2026
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.
@ramonsmits ramonsmits force-pushed the otel-service-names branch from a61e0b6 to 560fba3 Compare June 15, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant