Skip to content
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

[connector/spanmetricsv2] Scale spans based on adjusted count #95

Merged
merged 9 commits into from
Sep 13, 2024

Conversation

lahsivjar
Copy link
Contributor

@lahsivjar lahsivjar commented Aug 15, 2024

Calculates the adjusted count based on OTEP-235. Adjusted count represents the number of spans that a single sampled span represents -- similar to APM's representative count. OTEP-235 is now supported by probabilistic sampler too.

The logic should probably be controlled with a config option but that is not done yet.

Related to: https://github.com/elastic/opentelemetry-dev/issues/378
Also, related to: https://github.com/elastic/opentelemetry-dev/issues/372

@lahsivjar lahsivjar requested a review from a team as a code owner August 15, 2024 16:15
Copy link

@gregkalapos gregkalapos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here looks good to me.

I asked agent devs if we get r,p value or th by default, but it seems even th is not always propagated by probabilistic samplers. I think there isn't much we can do about this now and the PR makes the situation better, so 👍 from me.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. If we're planning to upstream this, then I think having the p-value handling in there may be problematic.

The logic should probably be controlled with a config option but that is not done yet.

In case you haven't seen it yet: open-telemetry/opentelemetry-collector-contrib#33632

connector/spanmetricsconnectorv2/connector.go Outdated Show resolved Hide resolved
Comment on lines 117 to 148
// For consistent probablity sampler, calculate the adjusted count based on
// p-value, negative base-2 logarithm of sampling probability
var p uint64
for _, kv := range otTraceState.ExtraValues() {
if kv.Key == "p" {
// If p-value is present then calculate the adjusted count as per
// the consistent probability sampling specs.
if kv.Value != "" {
// p-value is represented as unsigned decimal integers
// requiring at most 6 bits of information. We parse to
// 7 bits as 63 holds a special meaning and thus needs
// to be distinguished w.r.t. other invalid >63 values.
p, _ = strconv.ParseUint(kv.Value, 10, 7)
}
break
}
}
switch {
case p == 0:
return 1
case p == 63:
// p-value == 63 represents zero adjusted count
return 0
case p > 63:
// Invalid value, default to 1
return 1
default:
// TODO (lahsivjar): Should we handle fractional adjusted count?
// One way to do this would be to scale the values in the histograms
// for some precision.
return uint64(math.Pow(2, float64(p)))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this...

My understanding is that the old (experimental) p-value/r-value spec is superseded by OTEP 235, which introduces t-value.

If we need to support both, perhaps it should be a separate processor that transforms the old tracestate? We might want to do something similar to handle the Elastic APM tracestate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the old (experimental) p-value/r-value spec is superseded by OTEP 235, which introduces t-value.

+1. I didn't know that probabilistic sampling processor already supported the new specs and wanted to continue supporting that processor.

If we need to support both, perhaps it should be a separate processor that transforms the old tracestate? We might want to do something similar to handle the Elastic APM tracestate.

This makes more sense. I have updated the PR to remove the p-value handling in favor of OTEP 235.

@lahsivjar lahsivjar requested a review from axw September 11, 2024 10:40
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks for simplifying!

@lahsivjar lahsivjar merged commit cf1086b into elastic:main Sep 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants