This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Fix sampling when jaeger-baggage
header is given
#542
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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
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
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,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* Copyright (c) 2018, The Jaeger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
|
@@ -16,68 +16,50 @@ | |
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import io.jaegertracing.internal.Constants; | ||
import io.jaegertracing.internal.JaegerSpan; | ||
import io.jaegertracing.internal.JaegerSpanContext; | ||
import io.jaegertracing.internal.JaegerTracer; | ||
import io.jaegertracing.internal.reporters.InMemoryReporter; | ||
import io.jaegertracing.internal.samplers.ConstSampler; | ||
import io.opentracing.References; | ||
import io.opentracing.Scope; | ||
import io.opentracing.ScopeManager; | ||
import io.opentracing.Span; | ||
import io.opentracing.propagation.Format; | ||
import io.opentracing.propagation.TextMap; | ||
import io.opentracing.propagation.TextMapExtractAdapter; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class PropagationTest { | ||
@Test | ||
public void testDebugCorrelationId() { | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(new InMemoryReporter()) | ||
public class ActiveSpanTest { | ||
InMemoryReporter reporter; | ||
JaegerTracer tracer; | ||
|
||
@Before | ||
public void setUp() { | ||
reporter = new InMemoryReporter(); | ||
tracer = | ||
new JaegerTracer.Builder("TracerTestService") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
Map<String, String> headers = Collections.singletonMap(Constants.DEBUG_ID_HEADER_KEY, "Coraline"); | ||
TextMap carrier = new TextMapExtractAdapter(headers); | ||
|
||
JaegerSpanContext jaegerSpanContext = tracer.extract(Format.Builtin.TEXT_MAP, carrier); | ||
assertNotNull(jaegerSpanContext); | ||
assertTrue(jaegerSpanContext.isDebugIdContainerOnly()); | ||
assertEquals("Coraline", jaegerSpanContext.getDebugId()); | ||
|
||
JaegerSpan span = tracer.buildSpan("span").asChildOf(jaegerSpanContext).start(); | ||
jaegerSpanContext = span.context(); | ||
assertTrue(jaegerSpanContext.isSampled()); | ||
assertTrue(jaegerSpanContext.isDebug()); | ||
assertEquals("Coraline", span.getTags().get(Constants.DEBUG_ID_HEADER_KEY)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to AdhocHeadersTest |
||
} | ||
|
||
@Test | ||
public void testActiveSpan() { | ||
JaegerSpan mockSpan = Mockito.mock(JaegerSpan.class); | ||
tracer.scopeManager().activate(mockSpan, true); | ||
assertEquals(mockSpan, tracer.activeSpan()); | ||
} | ||
|
||
@Test | ||
public void testActiveSpanPropagation() { | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(new InMemoryReporter()) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
try (Scope parent = tracer.buildSpan("parent").startActive(true)) { | ||
assertEquals(parent, tracer.scopeManager().active()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testActiveSpanAutoReference() { | ||
InMemoryReporter reporter = new InMemoryReporter(); | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
try (Scope ignored = tracer.buildSpan("parent").startActive(true)) { | ||
tracer.buildSpan("child").startActive(true).close(); | ||
} | ||
|
@@ -101,22 +83,12 @@ public void testActiveSpanAutoReference() { | |
|
||
@Test | ||
public void testActiveSpanAutoFinishOnClose() { | ||
InMemoryReporter reporter = new InMemoryReporter(); | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
tracer.buildSpan("parent").startActive(true).close(); | ||
assertEquals(1, reporter.getSpans().size()); | ||
} | ||
|
||
@Test | ||
public void testActiveSpanNotAutoFinishOnClose() { | ||
InMemoryReporter reporter = new InMemoryReporter(); | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
Scope scope = tracer.buildSpan("parent").startActive(false); | ||
Span span = scope.span(); | ||
scope.close(); | ||
|
@@ -127,11 +99,6 @@ public void testActiveSpanNotAutoFinishOnClose() { | |
|
||
@Test | ||
public void testIgnoreActiveSpan() { | ||
InMemoryReporter reporter = new InMemoryReporter(); | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
try (Scope ignored = tracer.buildSpan("parent").startActive(true)) { | ||
tracer.buildSpan("child").ignoreActiveSpan().startActive(true).close(); | ||
} | ||
|
@@ -150,12 +117,6 @@ public void testIgnoreActiveSpan() { | |
|
||
@Test | ||
public void testNoAutoRefWithExistingRefs() { | ||
InMemoryReporter reporter = new InMemoryReporter(); | ||
JaegerTracer tracer = new JaegerTracer.Builder("test") | ||
.withReporter(reporter) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
|
||
JaegerSpan initialSpan = tracer.buildSpan("initial").start(); | ||
|
||
try (Scope ignored = tracer.buildSpan("parent").startActive(true)) { | ||
|
@@ -204,4 +165,18 @@ public Scope active() { | |
}).build(); | ||
assertEquals(scope, tracer.scopeManager().active()); | ||
} | ||
|
||
|
||
@Test | ||
public void testCustomSpanOnSpanManager() { | ||
// prepare | ||
Span activeSpan = mock(Span.class); | ||
ScopeManager scopeManager = tracer.scopeManager(); | ||
|
||
// test | ||
scopeManager.activate(activeSpan, false); | ||
|
||
// check | ||
assertEquals(activeSpan, tracer.activeSpan()); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
jaeger-core/src/test/java/io/jaegertracing/internal/AdhocHeadersTest.java
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,93 @@ | ||
/* | ||
* Copyright (c) 2018, The Jaeger Authors. | ||
* Copyright (c) 2016-2017, Uber Technologies, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.jaegertracing.internal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.jaegertracing.internal.reporters.InMemoryReporter; | ||
import io.jaegertracing.internal.samplers.ConstSampler; | ||
import io.opentracing.Span; | ||
import io.opentracing.propagation.Format; | ||
import io.opentracing.propagation.TextMap; | ||
import io.opentracing.propagation.TextMapExtractAdapter; | ||
import io.opentracing.propagation.TextMapInjectAdapter; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class AdhocHeadersTest { | ||
JaegerTracer tracer; | ||
|
||
@Before | ||
public void setUp() { | ||
tracer = | ||
new JaegerTracer.Builder("TracerTestService") | ||
.withReporter(new InMemoryReporter()) | ||
.withSampler(new ConstSampler(true)) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testDebugCorrelationId() { | ||
Map<String, String> headers = Collections.singletonMap(Constants.DEBUG_ID_HEADER_KEY, "Coraline"); | ||
TextMap carrier = new TextMapExtractAdapter(headers); | ||
|
||
JaegerSpanContext inboundSpanContext = tracer.extract(Format.Builtin.TEXT_MAP, carrier); | ||
assertNotNull(inboundSpanContext); | ||
assertFalse(inboundSpanContext.hasTrace()); | ||
assertEquals("Coraline", inboundSpanContext.getDebugId()); | ||
|
||
JaegerSpan span = tracer.buildSpan("span").asChildOf(inboundSpanContext).start(); | ||
JaegerSpanContext serverSpanContext = span.context(); | ||
assertTrue(serverSpanContext.isSampled()); | ||
assertTrue(serverSpanContext.isDebug()); | ||
assertEquals("Coraline", span.getTags().get(Constants.DEBUG_ID_HEADER_KEY)); | ||
} | ||
|
||
|
||
@Test | ||
public void testStartTraceWithAdhocBaggage() { | ||
traceWithAdhocBaggage(new HashMap<String, String>()); | ||
} | ||
|
||
@Test | ||
public void testJoinTraceWithAdhocBaggage() { | ||
Span span = tracer.buildSpan("test").start(); | ||
Map<String, String> headers = new HashMap<String, String>(); | ||
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(headers)); | ||
assertEquals(1, headers.size()); | ||
|
||
traceWithAdhocBaggage(headers); | ||
} | ||
|
||
private void traceWithAdhocBaggage(Map<String, String> headers) { | ||
headers.put("jaeger-baggage", "k1=v1, k2 = v2"); | ||
|
||
JaegerSpanContext parent = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers)); | ||
JaegerSpan span = tracer.buildSpan("test").asChildOf(parent).start(); | ||
|
||
assertTrue(span.context().isSampled()); | ||
assertEquals("must have baggage", "v1", span.getBaggageItem("k1")); | ||
assertEquals("must have baggage", "v2", span.getBaggageItem("k2")); | ||
} | ||
} |
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
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.
Copyright (c) 2016-2017, Uber Technologies, Inc
?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.
Nope, considering that active span did not exist in 2016 and most of 2017, and it was all implemented by people not from Uber.