-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On browser setting window.OTEL_SERVICE_NAME does not populate service.name #5043
Comments
@shanshanzhu What language is this related to? |
@theletterf Javascript run on browser (not nodeJS) |
@open-telemetry/javascript-approvers Could you have a look? @shanshanzhu Could you provide the specific doc where this appears? |
(Warning: I don't know the Web side of the OTel code very well, so I might get this wrong.) The automatic handling of That means you have to do it manually. Starting from https://opentelemetry.io/docs/languages/js/getting-started/browser/ // ...
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
const provider = new WebTracerProvider();
// ... That WebTracerProvider takes a TracerConfig takes a The "service name" for OpenTelemetry data is defined in a "resource" object. Option 1 is to manually create a resource: // ...
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { Resource } from '@opentelemetry/resources';
const resource = new Resource({
'service.name': 'my-service',
});
const provider = new WebTracerProvider({ resource });
// ... Option 2 is to use the (not documented in its README) import { envDetectorSync, detectResourcesSync } from '@opentelemetry/resources';
const resource = detectResourcesSync({detectors: [envDetectorSync]});
// ... I put "environment variables" in quotes, because the concept isn't really a thing in a browser. However, for now at least, the OTel JS browser code supports reading |
Yes, this should definitely be documented. I feel a little out of my depth tackling the Web JS docs. I suppose for a start we could add some reference docs to https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-web/README.md mentioning use of the resource to set service name. Likewise the https://opentelemetry.io/docs/languages/js/getting-started/browser/ page should mention setting service name. Setting service name is so important to using OTel data meaningfully that I feel like I may be missing something in these docs or in the code defaults. |
@trentm who would be the best person from the JS SIG to help with that? |
@open-telemetry/javascript-approvers PTAL, is this something we can fix? |
@svrnm - sorry just saw this: If I had to recommend a way, I'd recommend Option 1 that @trentm mentioned, doing it manually: // ...
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { Resource } from '@opentelemetry/resources';
const resource = new Resource({
'service.name': 'my-service',
});
const provider = new WebTracerProvider({ resource });
// ... I talked to the other JS SIG Maintainers recently, and we concluded that the whole |
thanks, so the best way to solve this is adding these instructions to the getting started guide I guess? |
Yes, I think so. And then, I guess https://opentelemetry.io/docs/languages/js/resources/#adding-resources-with-environment-variables should be made clear that it is talking about Node.js and not JS in the browser. |
Setting
window.OTEL_SERVICE_NAME
should populate service.name. Or please document the correct way to populate service.name in browser request (Not node)The text was updated successfully, but these errors were encountered: