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 OpenTelemetry API instructions for custom test tags #27474

Merged
merged 2 commits into from
Feb 7, 2025
Merged
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
58 changes: 54 additions & 4 deletions content/en/tests/setup/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,33 @@ The tracer exposes a set of APIs that can be used to extend its functionality pr

### Adding custom tags to tests

To add custom tags include [opentracing-util][4] library as a compile-time dependency to your project.
{{< tabs >}}
{{% tab "OpenTelemetry API" %}}

To add custom tags, include the [opentelemetry-api][1] library as a compile-time dependency and set `dd.trace.otel.enabled` (system property) or `DD_TRACE_OTEL_ENABLED` (environment variable) to `true`.

You can then add custom tags to your tests by using the active span:

```java
import io.opentelemetry.api.trace.Span;

// ...
// inside your test
Span span = Span.current();
span.setAttribute("test_owner", "my_team");
// test continues normally
// ...
```

For more information about adding tags, see the [Adding Tags][2] section of the Java custom instrumentation documentation.

[1]: https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-api
[2]: /tracing/trace_collection/custom_instrumentation/java?tab=locally#adding-tags

{{% /tab %}}
{{% tab "OpenTracing API" %}}

To add custom tags, include the [opentracing-util][1] library as a compile-time dependency to your project.

You can then add custom tags to your tests by using the active span:

Expand All @@ -230,12 +256,35 @@ if (span != null) {

To create filters or `group by` fields for these tags, you must first create facets.

For more information about adding tags, see the [Adding Tags][5] section of the Java custom instrumentation documentation.
For more information about adding tags, see the [Adding Tags][2] section of the Java custom instrumentation documentation.

[1]: https://mvnrepository.com/artifact/io.opentracing/opentracing-util
[2]: /tracing/trace_collection/custom_instrumentation/java?tab=locally#adding-tags

{{% /tab %}}
{{< /tabs >}}

### Adding custom measures to tests

Just like tags, you can add custom measures to your tests by using the current active span:

{{< tabs >}}
{{% tab "OpenTelemetry API" %}}

```java
import io.opentelemetry.api.trace.Span;

// ...
// inside your test
Span span = Span.current();
span.setAttribute("test.memory.usage", 1e8);
// test continues normally
// ...
```

{{% /tab %}}
{{% tab "OpenTracing API" %}}

```java
import io.opentracing.Span;
import io.opentracing.util.GlobalTracer;
Expand All @@ -250,6 +299,9 @@ if (span != null) {
// ...
```

{{% /tab %}}
{{< /tabs >}}

For more information about custom measures, see the [Add Custom Measures guide][6].

### Using manual testing API
Expand Down Expand Up @@ -483,8 +535,6 @@ To disable all integrations, augment the list of `-javaagent` arguments with `dd
[1]: #using-manual-testing-api
[2]: https://app.datadoghq.com/ci/setup/test?language=java
[3]: /tracing/trace_collection/library_config/java/?tab=containers#configuration
[4]: https://mvnrepository.com/artifact/io.opentracing/opentracing-util
[5]: /tracing/trace_collection/custom_instrumentation/java?tab=locally#adding-tags
[6]: /tests/guides/add_custom_measures/?tab=java
[7]: https://mvnrepository.com/artifact/com.datadoghq/dd-trace-api
[8]: /tests/#parameterized-test-configurations
Expand Down
Loading