generated from honeycombio/.github
-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Allow defining page.route
#185
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createBrowserRouter, useParams } from 'react-router-dom'; | ||
|
||
function Hello({ name }: { name?: string }) { | ||
const params = useParams(); | ||
const paramName = params['name']; | ||
return <h1>Hello {paramName ?? name}!</h1>; | ||
} | ||
export const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: <Hello name="world" />, | ||
}, | ||
{ | ||
path: '/:name', | ||
element: <Hello />, | ||
}, | ||
]); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
import { Span } from '@opentelemetry/api'; | ||
import { SpanProcessor } from '@opentelemetry/sdk-trace-base'; | ||
import { DynamicAttributesSpanProcessor } from './dynamic-attributes-span-processor'; | ||
|
||
function getBrowserAttributes() { | ||
const { href, pathname, search, hash, hostname } = window.location; | ||
|
||
return { | ||
'browser.width': window.innerWidth, | ||
'browser.height': window.innerHeight, | ||
'page.hash': hash, | ||
'page.url': href, | ||
'page.route': pathname, | ||
'page.hostname': hostname, | ||
'page.search': search, | ||
|
||
'url.path': pathname, | ||
}; | ||
} | ||
|
||
/** | ||
* A {@link SpanProcessor} that adds browser specific attributes to each span | ||
* that might change over the course of a session. | ||
* Static attributes (e.g. User Agent) are added to the Resource. | ||
*/ | ||
export class BrowserAttributesSpanProcessor implements SpanProcessor { | ||
constructor() {} | ||
|
||
onStart(span: Span) { | ||
const { href, pathname, search, hash, hostname } = window.location; | ||
|
||
span.setAttributes({ | ||
'browser.width': window.innerWidth, | ||
'browser.height': window.innerHeight, | ||
'page.hash': hash, | ||
'page.url': href, | ||
'page.route': pathname, | ||
'page.hostname': hostname, | ||
'page.search': search, | ||
|
||
'url.path': pathname, | ||
}); | ||
} | ||
|
||
onEnd() {} | ||
|
||
forceFlush() { | ||
return Promise.resolve(); | ||
} | ||
|
||
shutdown() { | ||
return Promise.resolve(); | ||
export class BrowserAttributesSpanProcessor extends DynamicAttributesSpanProcessor { | ||
constructor() { | ||
super({ getAttributes: getBrowserAttributes }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Attributes, Span } from '@opentelemetry/api'; | ||
import { SpanProcessor } from '@opentelemetry/sdk-trace-base'; | ||
|
||
interface PageRouteSpanProcessorOptions { | ||
getAttributes: () => Attributes; | ||
} | ||
|
||
/** | ||
* A {@link SpanProcessor} that adds dynamic attributes to every span | ||
*/ | ||
export class DynamicAttributesSpanProcessor implements SpanProcessor { | ||
private getAttributes: () => Attributes; | ||
constructor(options: PageRouteSpanProcessorOptions) { | ||
this.getAttributes = options.getAttributes; | ||
} | ||
|
||
onStart(span: Span) { | ||
const attributes = this.getAttributes(); | ||
span.setAttributes(attributes); | ||
} | ||
|
||
onEnd() {} | ||
|
||
forceFlush() { | ||
return Promise.resolve(); | ||
} | ||
|
||
shutdown() { | ||
return Promise.resolve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './base-otel-sdk'; | ||
export * from './honeycomb-otel-sdk'; | ||
export * from './web-vitals-autoinstrumentation'; | ||
export * from './dynamic-attributes-span-processor'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@pkanal, I started thinking that maybe a
PageRouteSpanProcessor
makes less sense than something more generic, so here is aDynamicAttributesSpanProcessor
which can be exposed and theBrowserAttributesSpanProcessor
can be implemented in terms of. This would avoid needing to introduce a separate processor for each little attribute that comes up over time.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 like this approach! I'm wondering whether this should be something we package with the SDK or whether this should be documented for users since everyone's use case will be slightly different? 🤔
Thoughts @wolfgangcodes / @MustafaHaddara ?
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'm arriving at the same conclusion. I think adding dynamic attributes globally like this will be a common use case, but at the same time this is so exceedingly generic as to be almost worthless. I'm hoping that sometime soon the OTel client instrumentation SIG comes up with a proposal to allow dynamic resource attributes which might fit these use cases better. At that point the
page.route
thing is something you'd just set up in your render cycle with atrace.addResourceAttributes({ 'page.route': match.route })
and would also take care of things like changing theenduser.id
ortenant.id
when a user logs in during a session.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.
Hmmmm yeah, I think that is what span processors are meant to do in general. So are we coming to the conclusion that the best thing to do here is make sure that this distro is able to support multiple span processors and that this should be expressed as a custom span processor in a consuming app?
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, agreed, I'll close this PR