-
Notifications
You must be signed in to change notification settings - Fork 733
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
Browser identification resource attributes #3201
Browser identification resource attributes #3201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing to the project!
However, I don't think this is the expected approach to adding browser resources. This should be added to the ResourceDetector implementation, like https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts.
BTW, you'll need to sign the CLA before we can accept your contribution.
Thanks for reviewing. I have signed the CLA. And regarding the BrowserDetector, I don't see it being used anywhere except in the tests. Is it possible to use it in the WebTraceProvider to initialize the browser resource attributes ? what is your thought on how to do this ? |
@Abinet18 we currently didn't automatically detect resources in the web packages. The detector has to be invoked manually to detect browser resource attributes. Ideally, we can create a package As the first step, I'd encourage adding support to detect the new resource attributes in the browser resource detector. |
I have done as you advised, brought the attribute addition to the Browser detector. I also wanted to use SemanticResourceAttributes for the attribute names but these names are not yet included there ? |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3201 +/- ##
==========================================
- Coverage 93.28% 92.36% -0.92%
==========================================
Files 201 195 -6
Lines 6579 6118 -461
Branches 1379 1291 -88
==========================================
- Hits 6137 5651 -486
- Misses 442 467 +25
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your work on this! Can you also cover the new feature with a test please?
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM! Just a few nits.
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
browserAttribs['browser.brands'] = userAgentData.brands; | ||
browserAttribs['browser.mobile'] = userAgentData.mobile; | ||
} | ||
browserAttribs['browser.user_agent'] = navigator.userAgent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the semantic convention attributes, we can create a constant map for it and add a comment that it should be replaced once the semantic convention package is updated. So that we don't need to repeat these constants here and in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the change is as you requested. Also we have redundant attributes in version and user_agent. What do you suggest ?
packages/opentelemetry-resources/test/util/resource-assertions.ts
Outdated
Show resolved
Hide resolved
@@ -31,7 +31,8 @@ class BrowserDetector implements Detector { | |||
const browserResource: ResourceAttributes = { | |||
[SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser', | |||
[SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Web Browser', | |||
[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: navigator.userAgent | |||
[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: navigator.userAgent, | |||
...getBrowserAttributes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinkuba can you review this - the process.runtime.*
attributes were here before you added the browser.*
attributes in the semantic conventions - do we really need process.runtime.* attributes as part of BrowserDetector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe removing the existing attributes from the detector can be breaking. As the browser.*
attributes are the newer ones, is it possible to remove the duplicated entry browser.user_agent
?
browserAttribs[BROWSER_ATTRIBUTES.BRANDS] = userAgentData.brands; | ||
browserAttribs[BROWSER_ATTRIBUTES.MOBILE] = userAgentData.mobile; | ||
} | ||
browserAttribs[BROWSER_ATTRIBUTES.USER_AGENT] = navigator.userAgent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinkuba do we need to include the user_agent
attribute even when platform
, brands
and mobile
are present or only when they are not available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent was to include it only when the userAgentData API is not available, so that backends move to using the new API. Parsing the userAgent string should only be done to support old browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I then remove the user_agent attribute. The runtime version attribute is always added and it is the userAgent, so browsers that don't support userAgentData can parse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process.runtime.*
attributes should be deprecated in browser resource attributes now that we have browser.*
attributes in the spec. However, browser.user_agent
should be included only in an else block when userAgentData
isn't supported by the browser.
I wonder what the process for this deprecation is. Just add to changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process.runtime.version
attribute probably should no longer be used for browsers, so that the user-agent string is not sent twice. But I am not sure that process.runtime.name
should be deprecated. All of the browser
attributes are optional, so it is possible that they would not be sent if the browser does not provide them. On the other hand, the value for process.runtime.name
is the static value browser
; it is added by the SDK without detecting anything, which makes it more reliable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@legendecas Can you respond to my comment above? We could discuss it in the JS SIG too this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response.
The intention of the specified attributes is to write down what's already shipped.
As you mentioned removing existing attributes can be breaking. Package @opentelemetry/resource is declared stable so I'm not sure about introducing such a change to the existing API is fine. One possible solution is to add a new detector like UserAgentDataDetector
, which implements the newer browser.*
attributes, and in the meantime, we can mark the BrowserDetector
as deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So , Do you mean that we should drop this change and create a new Detector for the user-agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if we need to avoid reporting the legacy process attributes for the browser, we may add a new detector to not introduce breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed in the JS SIG today 9/14 - it was suggested that we add the new detector in a separate package in the experimental folder so that its release can be managed independently.
Separately, I will submit a PR to the spec repo and get the process.runtime.* attributes removed for the browser case, after we which we can mark the BrowserDetector
in this package as deprecated.
Which problem is this PR solving?
For all the traces that are generated from browser ,we need to have the browser identifier attributes like platform, brands, mobile, and user_agent. Instead of adding these attributes to individual spans, it is better if we have them as part of resource attributes which will be common for all the traces. This PR is adding these attributes at WebTracerProvider level.
Short description of the changes
At WebTracerProvider add these browser identifier attributes to the config and pass it to the trace provider constructor.
Please delete options that are not relevant.
How Has This Been Tested?
The change is tested on a sample app that uses the otel instrumentation libraries for browser and confirming that the resource attributes include the ones added here
Checklist: