Skip to content

Respect OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES #20502

Description

@ChristopherChudzicki

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

10.50.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

See below

// Minimal repro for Sentry OTEL service.name behavior.
// Run with:
//   OTEL_SERVICE_NAME=my-app OTEL_RESOURCE_ATTRIBUTES=service.namespace=my-namespace,other_attr=foo node sentry_otel_service_name.js

const Sentry = require("@sentry/node")

Sentry.init({
  dsn: "https://public@example.ingest.sentry.io/1",
  tracesSampleRate: 1.0,
})

const client = Sentry.getClient()
const traceProvider = client?.traceProvider
const resource =
  traceProvider?._resource ?? traceProvider?._config?.resource ?? null
const resourceAttrs = resource?.attributes ?? {}

console.log("OTEL_SERVICE_NAME env:", process.env.OTEL_SERVICE_NAME)
console.log(
  "OTEL_RESOURCE_ATTRIBUTES env:",
  process.env.OTEL_RESOURCE_ATTRIBUTES,
)
console.log("traceProvider resource attributes:", resourceAttrs)

Steps to Reproduce

  1. Save script above as sentry_otel_service_name.js with @sentry/node installed at v10.50.0
  2. Run OTEL_SERVICE_NAME=my-app OTEL_RESOURCE_ATTRIBUTES=service.namespace=learn-local,other_attr=foo node sentry_otel_service_name.js
  3. Observe the output:
OTEL_SERVICE_NAME env: my-app
OTEL_RESOURCE_ATTRIBUTES env: service.namespace=my-namespace,other_attr=foo
traceProvider resource attributes: {
  'service.name': 'node',
  'service.namespace': 'sentry',
  'service.version': '10.50.0',
  'telemetry.sdk.language': 'nodejs',
  'telemetry.sdk.name': 'opentelemetry',
  'telemetry.sdk.version': '2.7.0'
}

Expected Result

The OTEL setup should respect OTEL_SERVICE_NAME. It would be great to also respect OTEL_RESOURCE_ATTRIBUTES

With the script above, I would expect:

traceProvider resource attributes: {
  'service.name': 'my-app',
  'service.namespace': 'my-namespace',
  'service.version': '10.50.0',
  'telemetry.sdk.language': 'nodejs',
  'telemetry.sdk.name': 'opentelemetry',
  'telemetry.sdk.version': '2.7.0'
  other_attr: 'foo'
}

Actual Result

OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES are ignored. Sentry always uses OTEL_SERVICE_NAME as the service.name value. (See steps to reproduce above.)

Workaround: Application code adds a custom span/resource override processor to rewrite resource attributes (service.name, service.namespace, service.version) before export.

Additional Context

resource: getSentryResource('node'),
seems to be where service.name gets set to "node".

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

Labels

BugNode.jsjavascriptPull requests that update javascript code

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions