Skip to content

Add a resourceDetectors configuration to the SDK #3210

Closed
@svrnm

Description

Is your feature request related to a problem? Please describe.

Since we had an internal need for that, I wanted to write down a small sample where I use the NodeSDK with some additional resource detectors (docker, aws). Unfortunately I can not add them without a lot of additional code.

Eventually I wanted to add this to the JS docs over at opentelemetry.io so having something user-friendly is what I am looking for

Describe the solution you'd like

I found this list in opentelemetry-sdk-node package and I was hoping that it would be feasible to make this list extendible with an interface that looks like this:

import { dockerCGroupV1Detector } from '@opentelemetry/resource-detector-docker'
import { awsEc2Detector } from '@opentelemetry/resource-detector-aws'

const sdk = new opentelemetry.NodeSDK({
   traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
   instrumentations: [getNodeAutoInstrumentations()],
   resourceDetectors: [dockerCGroupV1Detector, awsEc2Detector]
});

Describe alternatives you've considered

What I can do right now is either overwriting the OTEL_RESOURCE_ATTRIBUTES with the attributes I want or I can do something like this (via this thread from @osherv:

const detectedResources = await detectResources({
    detectors: [envDetector, processDetector, dockerCGroupV1Detector, awsEc2Detector],
  });

  const myResource = new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: "serviceName",
    ["my.custom.attr"]: "someValue",
  });

const sdk = new opentelemetry.NodeSDK({
  traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
  instrumentations: [getNodeAutoInstrumentations()],
   resource:  myResource.merge(detectedResources),
  autoDetectResources: false
});

Additional context

@osherv agreed to pick this up, if @open-telemetry/javascript-maintainers agree that this would be a good addition to the NodeSDK

Side Note: Eventually it would be cool to have a package like @opentelemetry/auto-instrumentations-node for resource detection that would allow something like resourceDetectors: getNodeResourceDetectors()

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions