The following code is inside a instrumentation.js file:
const { NodeSDK } = require('@opentelemetry/sdk-node');
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'xyz',
[SemanticResourceAttributes.SERVICE_VERSION]: '1.2.3',
}),
...
}
sdk.start();
When running applications in production, a flag to --require the instrumentation.js is added to the node command, as outlined in the Getting Started > Node.js documentation:
$ node --require ./instrumentation.js app.js
Application developers currently have no access to this instrumentation.js file.
Is there a way for application developers to retrieve the resource attributes from within their applications (app.js) for logging, without access to instrumentation.js?
- If I have a reference to the resource, I can get the attributes using
resource.attributes. But how do I get a reference to that resource within the application? @opentelemetry/apiprovides agetTracerProvider()method to get the current globally-registeredTracerProvider. Is there an equivalentgetResource()?
Got a reply from one of the maintainers of
opentelemetry-js: