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

Enable Add Events tests for Java #2875

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/scenarios/parametric.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ Add a file datadog-dotnet-apm-<VERSION>.tar.gz in binaries/. <VERSION> must be a

##### Run Parametric tests with a custom Java Tracer version

1. Build Java Tracer artifacts
1. Clone the repo and checkout to the branch you'd like to test
Clone the repo:
```bash
git clone [email protected]:DataDog/dd-trace-java.git
cd dd-trace-java
```
By default you will be on the `master` branch, but if you'd like to run system-tests on the changes you made to your local branch, `gitc checkout` to that branch.

1. Build Java Tracer artifacts
```bash
./gradlew :dd-java-agent:shadowJar :dd-trace-api:jar
```

Expand Down
6 changes: 3 additions & 3 deletions tests/parametric/test_otel_span_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def test_otel_span_extended_reserved_attributes_overrides_analytics_event(
context.library != "[email protected]" and context.library < "[email protected]", reason="Implemented in v1.67.0"
)
@missing_feature(context.library == "php", reason="Not implemented")
@missing_feature(context.library == "java", reason="Not implemented")
@missing_feature(context.library < "java@1.39.0", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Implemented in v5.17.0 & v4.41.0")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
Expand Down Expand Up @@ -922,7 +922,7 @@ def test_otel_add_event_meta_serialization(self, test_agent, test_library):

@missing_feature(context.library == "golang", reason="Not implemented")
@missing_feature(context.library == "php", reason="Not implemented")
@missing_feature(context.library == "java", reason="Not implemented")
@missing_feature(context.library < "java@1.39.0", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Implemented in v5.17.0 & v4.41.0")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
Expand All @@ -943,7 +943,7 @@ def test_otel_record_exception_does_not_set_error(self, test_agent, test_library

@missing_feature(context.library == "golang", reason="Not implemented")
@missing_feature(context.library == "php", reason="Not implemented")
@missing_feature(context.library == "java", reason="Not implemented")
@missing_feature(context.library < "java@1.39.0", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
@missing_feature(context.library < "[email protected]", reason="Implemented in v5.17.0 & v4.41.0")
@missing_feature(context.library < "[email protected]", reason="Not implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.datadoghq.client.APMClientGrpc;
import com.datadoghq.client.ApmTestClient;
import com.datadoghq.client.ApmTestClient.OtelRecordExceptionArgs;
import com.datadoghq.client.ApmTestClient.OtelRecordExceptionReturn;
import com.datadoghq.client.ApmTestClient.OtelEndSpanArgs;
import com.datadoghq.client.ApmTestClient.OtelEndSpanReturn;
import com.datadoghq.client.ApmTestClient.OtelFlushSpansArgs;
Expand All @@ -43,6 +45,8 @@
import datadog.trace.api.Tracer;
import datadog.trace.api.internal.InternalTracer;
import io.grpc.stub.StreamObserver;
import com.datadoghq.client.ApmTestClient.OtelAddEventArgs;
import com.datadoghq.client.ApmTestClient.OtelAddEventReturn;

public class ApmCompositeClient extends APMClientGrpc.APMClientImplBase {
private final Tracer ddTracer;
Expand Down Expand Up @@ -147,6 +151,16 @@ public void otelSetAttributes(OtelSetAttributesArgs request, StreamObserver<Otel
this.otelClient.otelSetAttributes(request, responseObserver);
}

@Override
public void otelAddEvent(OtelAddEventArgs request, StreamObserver<OtelAddEventReturn> responseObserver) {
this.otelClient.otelAddEvent(request, responseObserver);
}

// @Override
// public void otelRecordException(OtelRecordExceptionArgs request, StreamObserver<OtelRecordExceptionReturn> responseObserver) {
// this.otelClient.otelRecordException(request, responseObserver);
// }

@Override
public void otelFlushSpans(OtelFlushSpansArgs request, StreamObserver<OtelFlushSpansReturn> responseObserver) {
LOGGER.info("Flushing OTel spans: {}", request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static datadog.trace.api.DDTags.RESOURCE_NAME;
import static datadog.trace.api.DDTags.SERVICE_NAME;
import static datadog.trace.api.DDTags.SPAN_TYPE;
import static java.util.concurrent.TimeUnit.MICROSECONDS;

import com.datadoghq.client.APMClientGrpc;
import com.datadoghq.client.ApmTestClient;
Expand Down Expand Up @@ -45,6 +44,9 @@
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.concurrent.TimeUnit;
import com.datadoghq.client.ApmTestClient.OtelAddEventArgs;
import com.datadoghq.client.ApmTestClient.OtelAddEventReturn;

public class OpenTelemetryClient extends APMClientGrpc.APMClientImplBase {
private final Tracer tracer;
Expand Down Expand Up @@ -165,7 +167,7 @@ public void otelStartSpan(OtelStartSpanArgs request, StreamObserver<OtelStartSpa
}
}
if (request.hasTimestamp()) {
builder.setStartTimestamp(request.getTimestamp(), MICROSECONDS);
builder.setStartTimestamp(request.getTimestamp(), TimeUnit.MICROSECONDS);
}
if (request.getSpanLinksCount() > 0) {
for (SpanLink spanLink : request.getSpanLinksList()) {
Expand Down Expand Up @@ -243,7 +245,7 @@ public void otelEndSpan(OtelEndSpanArgs request, StreamObserver<OtelEndSpanRetur
Span span = getSpan(request.getId(), responseObserver);
if (span != null) {
if (request.hasTimestamp()) {
span.end(request.getTimestamp(), MICROSECONDS);
span.end(request.getTimestamp(), TimeUnit.MICROSECONDS);
} else {
span.end();
}
Expand Down Expand Up @@ -342,6 +344,44 @@ public void otelSetAttributes(OtelSetAttributesArgs request, StreamObserver<Otel
}
}

@Override
public void otelAddEvent(OtelAddEventArgs request, StreamObserver<OtelAddEventReturn> responseObserver) {
LOGGER.info("Adding OTel span event: {}", request);
try {
Span span = getSpan(request.getSpanId(), responseObserver);
if (span != null) {
if (request.hasTimestamp()) {
// need to do some check to dynamically choose the time unit conversion?
span.addEvent(request.getName(), parseAttributes(request.getAttributes()), request.getTimestamp(), TimeUnit.MICROSECONDS);
} else {
span.addEvent(request.getName(), parseAttributes(request.getAttributes()));
}
responseObserver.onNext(OtelAddEventReturn.newBuilder().build());
responseObserver.onCompleted();
}
} catch (Throwable t) {
LOGGER.error("Uncaught throwable", t);
responseObserver.onError(t);
}
}

// @Override
// public void otelRecordException(OtelRecordExceptionArgs request, StreamObserver<OtelRecordExceptionReturn> responseObserver) {
// LOGGER.info("OTel record exception: {}", request);
// try {
// Span span = getSpan(request.getSpanId(), responseObserver);
// if (span != null) {
// span.recordException(new Exception(request.getMessage()), request.getAttributes());
// responseObserver.onNext(OtelRecordExceptionReturn.newBuilder().build());
// responseObserver.onCompleted();
// }
// } catch (Throwable t) {
// LOGGER.error("Uncaught throwable", t);
// responseObserver.onError(t);
// }
// }


private Span getSpan(long spanId, StreamObserver<?> responseObserver) {
Span span = this.spans.get(spanId);
if (span == null) {
Expand Down
Loading