-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(flags): track feature flag evaluations in span attributes #16475
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
Conversation
@@ -1,3 +1,5 @@ | |||
/* eslint-disable max-lines */ |
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.
304 lines after changes
@@ -45,6 +47,8 @@ import { timedEventsToMeasurements } from './measurement'; | |||
import { getCapturedScopesOnSpan } from './utils'; | |||
|
|||
const MAX_SPAN_COUNT = 1000; | |||
const MAX_FEATURE_FLAGS_PER_SPAN = 10; // The maximum number of feature flag evaluations that can be recorded in span attributes. | |||
const FEATURE_FLAG_ATTRIBUTE_PREFIX = 'sentry.flag.evaluation.'; |
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.
Since users can call setAttribute
, can be user defined I thought it best to prefix with sentry.
See SpanAttributes
defn
if (this._numFeatureFlags >= MAX_FEATURE_FLAGS_PER_SPAN) { | ||
return this; | ||
} |
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 this be a buffer so that we can evict the least recently added flags (similar to what we do w/ breadcrumbs)? Silently ignoring the flag here feels not great.
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.
It's what we do on in python atm, cc @cmanallen. We could have a buffer but need to make sure the attribute is serializable - Doesn't look like SpanAttributeValue allows nested objects. Maybe we could store a buffer of keys internally
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.
For spans the oldest flag evaluations are the most important because they're likely to have the largest performance impact. We drop late arrivals due to request size concerns.
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.
Is it expected that this will be used by users? Like they will call span.addFeatureFlag
?
A method on the span break our compat with OTEL spans, which we use for duck typing in some scenarios. I would prefer if we made this a helper method we export from @sentry/core
instead. You can see an example of this with setHttpStatus
:
export function setHttpStatus(span: Span, httpStatus: number): void { |
We're basically just extracting addFlagToActiveSpan
into core, with a implementation that looks something like so:
export function addFlagToSpan(span: Span, name: string, value: unknown): void {
if (!span || typeof value !== 'boolean') {
return;
}
span.setAttribute(`${FEATURE_FLAG_ATTRIBUTE_PREFIX}${name}`, value);
}
@@ -79,6 +79,11 @@ export class SentryNonRecordingSpan implements Span { | |||
return this; | |||
} | |||
|
|||
/** @inheritDoc */ | |||
public addFeatureFlag(_name: string, _value: boolean): this { |
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.
Adding a new method onto a span breaks our compatibility with OTEL, which we leverage for duck typing.
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.
This strategy makes sense, but how can we track the num current flags? (currently a protected field on the span)
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.
Is it expected that this will be used by users? Like they will call span.addFeatureFlag?
I'm thinking we can expose this as an API for users, following the pattern we have for adding flags to scope in featureFlagIntegration
. It'd be the same as the addFeatureFlag
method, without the need for an integration
Opening a new PR w/revised implementation |
Based off https://github.com/getsentry/sentry-python/pull/4280/files
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint
) & (yarn test
).