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

Add span kind to sampling overrides #1960

Merged
merged 9 commits into from
Nov 16, 2021
Merged

Conversation

trask
Copy link
Member

@trask trask commented Nov 12, 2021

it's currently hard to suppress all outgoing http client spans, since those have essentially the same attributes as incoming http server spans.

attaching snapshot for testing: applicationinsights-agent-3.2.4-BETA-SNAPSHOT.jar.zip

@@ -62,6 +63,25 @@ private static boolean isEmpty(String str) {
return str == null || str.trim().isEmpty();
}

public enum SpanKind {
@JsonProperty("server")
SERVER(io.opentelemetry.api.trace.SpanKind.SERVER),
Copy link
Contributor

Choose a reason for hiding this comment

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

is io.opentelemetry.api.trace.SpanKind an enum? can we reuse it rather than create a new one? if their spankind is updated, we shouldn't need to update ours.

Copy link
Member Author

Choose a reason for hiding this comment

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

our convention is for json enum values to be lowercase, and we can't add @JsonProperty to those classes since they are not under our control. I will add a TODO marker here to investigate other options for mapping external annotations to lowercase.

@@ -373,6 +393,8 @@ private static String getDefaultPath() {
}

public static class SamplingOverride {
// TODO (trask) consider making this required when moving out of preview
@Nullable public SpanKind spanKind;
Copy link
Contributor

Choose a reason for hiding this comment

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

declare it as io.opentelemetry.api.trace.SpanKind?

Copy link
Member Author

Choose a reason for hiding this comment

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

see comment above

void shouldFilterStrictMatchWithNullSpanKind() {
// given
List<SamplingOverride> overrides =
singletonList(newOverride(null, 0, newStrictAttribute("one", "1")));
Copy link
Contributor

Choose a reason for hiding this comment

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

when it's null, it will match any span kind?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

SamplingOverrides sampler = new SamplingOverrides(overrides);
Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1");

// expect
assertThat(sampler.getOverride(attributes).getPercentage()).isEqualTo(0);
assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

assertThat(sampler.getOverride(SpanKind.CLIENT, attributes).getPercentage))).isEqualTo(0); should work too?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

@trask trask merged commit 404f79c into main Nov 16, 2021
@trask trask deleted the add-span-kind-to-sampling-overrides branch November 16, 2021 19:21
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.

2 participants