Skip to content

Commit

Permalink
Bug 37474240 - [37474174->25.03] Span context not properly propagated…
Browse files Browse the repository at this point in the history
… when using Otel (merge main -> ce/main @ 113594)

[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 113596]
  • Loading branch information
rlubke committed Jan 17, 2025
1 parent cb06ac8 commit 0d06083
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -22003,6 +22003,8 @@ public void read(com.tangosol.io.ReadBuffer.BufferInput input)
{
setAllowBackupRead(input.readBoolean());
}

readTracing(input);
}

// Declared at the super level
Expand Down Expand Up @@ -22048,6 +22050,8 @@ public void write(com.tangosol.io.WriteBuffer.BufferOutput output)
super.write(output);

output.writeBoolean(isAllowBackupRead());

writeTracing(output);
}

// ---- class: com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$GetRequest$Poll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public Map<String, String> inject(SpanContext spanContext)
LiteMap<String, String> injectTarget = new LiteMap<>();
TextMapPropagator propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator();

propagator.inject(Context.current(), injectTarget, new MapSetter());
propagator.inject(Context.current().with(
io.opentelemetry.api.trace.Span.wrap(spanContext.underlying())), injectTarget, new MapSetter());

return injectTarget;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -86,35 +86,7 @@ public void testPutTracing(Validator validator)
NamedCache cache = getNamedCache();
assertThat(cache, is(notNullValue()));

final AtomicBoolean entryInserted = new AtomicBoolean();
final AtomicBoolean entryUpdated = new AtomicBoolean();
final AtomicBoolean entryDeleted = new AtomicBoolean();
cache.addMapListener(new MapListenerSupport.SynchronousListener()
{
@Override
public void entryInserted(MapEvent evt)
{
entryInserted.compareAndSet(false, true);
}

@Override
public void entryUpdated(MapEvent evt)
{
entryUpdated.compareAndSet(false, true);
}

@Override
public void entryDeleted(MapEvent evt)
{
entryDeleted.compareAndSet(false, true);
}
});

cache.put("a", "1");

assertThat("entryInserted not invoked", entryInserted.get(), is(true));
assertThat("entryUpdated incorrectly invoked", entryUpdated.get(), is(false));
assertThat("entryDeleted incorrectly invoked", entryDeleted.get(), is(false));
}, "PUT", validator));
}

Expand All @@ -133,36 +105,8 @@ public void testRemoveTracing(Validator validator)

cache.put("a", "1"); // not too interested in this event

final AtomicBoolean entryInserted = new AtomicBoolean();
final AtomicBoolean entryUpdated = new AtomicBoolean();
final AtomicBoolean entryDeleted = new AtomicBoolean();
cache.addMapListener(new MapListenerSupport.SynchronousListener()
{
@Override
public void entryInserted(MapEvent evt)
{
entryInserted.compareAndSet(false, true);
}

@Override
public void entryUpdated(MapEvent evt)
{
entryUpdated.compareAndSet(false, true);
}

@Override
public void entryDeleted(MapEvent evt)
{
entryDeleted.compareAndSet(false, true);
}
});

cache.remove("a");

assertThat("entryInserted incorrectly invoked", entryInserted.get(), is(false));
assertThat("entryUpdated incorrectly invoked", entryUpdated.get(), is(false));
assertThat("entryDeleted not invoked", entryDeleted.get(), is(true));
}, "PUT", validator));
}, "REMOVE", validator));
}

// ----- helper methods -------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
package opentelemetry.core;

import com.google.protobuf.ByteString;
import com.oracle.bedrock.runtime.coherence.CoherenceClusterMember;

import com.oracle.coherence.common.base.Blocking;
Expand Down Expand Up @@ -178,7 +179,12 @@ public void testGetTracing()
// validate server spans
listExpected = TestingUtils.getSpans(listAllSpans, new String[] {"Get.dispatch", "Get.process"}, 2);
assertThat(listExpected.size(), is(2));
listExpected.forEach(span -> validateTagsForSpan(span, false, TestingUtils.MutationType.none));
Span spanParent = listExpected.get(0);
listExpected.forEach(span ->
{
validateSpanAssociation(spanParent, span);
validateTagsForSpan(span, false, TestingUtils.MutationType.none);
});
});
}

Expand All @@ -190,15 +196,19 @@ public void testPutTracing()
List<Span> listAllSpans = TestingUtils.waitForAllSpans(m_collectorServer);

// validate client spans
List<Span> listExpected = TestingUtils.getSpans(listAllSpans,
new String[] { "Put.request", "FilterEvent.process" }, 1);
assertThat(listExpected.size(), is(2));
List<Span> listExpected = TestingUtils.getSpans(listAllSpans, new String[] { "Put.request"}, 1);
assertThat(listExpected.size(), is(1));
listExpected.forEach(span -> validateTagsForSpan(span, false, TestingUtils.MutationType.inserted));

// validate server spans
listExpected = TestingUtils.getSpans(listAllSpans, new String[] {"Put.dispatch", "Put.process"}, 2);
assertThat(listExpected.size(), is(2));
listExpected.forEach(span -> validateTagsForSpan(span, false, TestingUtils.MutationType.inserted));
Span spanParent = listExpected.get(0);
listExpected.forEach(span ->
{
validateSpanAssociation(spanParent, span);
validateTagsForSpan(span, false, TestingUtils.MutationType.inserted);
});
});
}

Expand All @@ -210,20 +220,32 @@ public void testRemoveTracing()
List<Span> listAllSpans = TestingUtils.waitForAllSpans(m_collectorServer);

// validate client spans
List<Span> listExpected = TestingUtils.getSpans(listAllSpans,
new String[] { "Remove.request", "FilterEvent.process" }, 1);
assertThat(listExpected.size(), is(2));
List<Span> listExpected = TestingUtils.getSpans(listAllSpans, new String[] { "Remove.request" }, 1);
assertThat(listExpected.size(), is(1));
listExpected.forEach(span -> validateTagsForSpan(span, false, TestingUtils.MutationType.deleted));

// validate server spans
listExpected = TestingUtils.getSpans(listAllSpans, new String[] {"Remove.dispatch", "Remove.process"}, 2);
assertThat(listExpected.size(), is(2));
listExpected.forEach(span -> validateTagsForSpan(span, false, TestingUtils.MutationType.deleted));
Span spanParent = listExpected.get(0);
listExpected.forEach(span ->
{
validateSpanAssociation(spanParent, span);
validateTagsForSpan(span, false, TestingUtils.MutationType.deleted);
});
});
}

// ----- helper methods -------------------------------------------------

/**
* Verify the trace-id for the starting span, is the same for inner spans.
*/
protected static void validateSpanAssociation(Span spanParent, Span spanAssociated)
{
assertThat("Trace IDs between parent and associated spans do not match", spanAssociated.getTraceId(), is(spanParent.getTraceId()));
}

/**
* Verify the tags contained within the provided {@link Span span} contains the expected keys and or keys/values.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -176,7 +176,7 @@ public void testPutTracing()
validateReporter((reporter) ->
{
JaegerSpan[] localSpans = validateOpsPresent(
new String[] {"Put.request", "FilterEvent.process"},
new String[] {"Put.request" },
AdaptiveTracerFactory.getReporter().getSpans());
Arrays.stream(localSpans).forEach(
span -> validateTagsForSpan(span, false, MutationType.inserted));
Expand All @@ -197,7 +197,7 @@ public void testRemoveTracing()
validateReporter((reporter) ->
{
JaegerSpan[] localSpans = validateOpsPresent(
new String[] {"Remove.request", "FilterEvent.process"},
new String[] {"Remove.request" },
AdaptiveTracerFactory.getReporter().getSpans());
Arrays.stream(localSpans).forEach(
span -> validateTagsForSpan(span, false, MutationType.deleted));
Expand Down

0 comments on commit 0d06083

Please sign in to comment.