Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
08507df
add agentless module for OpenTelemetry setup without any agent
adinauer Dec 6, 2024
b36339c
Replace bool with enum for OpenTelemetryUtil mode
adinauer Dec 16, 2024
d48d398
Move OpenTelemetryUtil into core sentry
adinauer Dec 16, 2024
66b4206
Add openTelemetryMode option
adinauer Dec 17, 2024
a0a4baa
Merge branch '8.x.x' into feat/add-opentelemetry-mode-option
adinauer Dec 17, 2024
e46efe8
Add SentryOpenTelemetryMode.OFF
adinauer Dec 17, 2024
5231140
fix HubAdapter and ScopeAdapter tests by calling Sentry.init so that …
lbloder Dec 17, 2024
917b2e3
Hold a strong reference to OTel span if created via Sentry API
adinauer Dec 17, 2024
b11af4d
add sentry-opentelemetry-agentless-spring module
adinauer Dec 18, 2024
77d60e4
fix tests
adinauer Dec 18, 2024
6b69f56
fix build
adinauer Dec 18, 2024
cb8746c
changelog
adinauer Dec 18, 2024
400b60e
fix agentless due to late call to SpanFactoryFactory
adinauer Dec 19, 2024
d444ef7
Format code
getsentry-bot Dec 19, 2024
3f891c4
Merge branch 'feat/add-opentelemetry-mode-option' into feat/otel-mode…
adinauer Dec 19, 2024
dacc35b
changelog
adinauer Dec 19, 2024
dd37382
fix order of scope storage close vs scopes close
adinauer Dec 19, 2024
a17517b
Merge branch 'feat/otel-mode-off' into feat/otel-span-strongref
adinauer Dec 19, 2024
f3056ff
changelog
adinauer Dec 19, 2024
9f71bec
Merge branch 'feat/otel-span-strongref' into feat/agentless-spring-mo…
adinauer Dec 19, 2024
63080b1
add PR link to changelog
adinauer Dec 19, 2024
68019c1
Merge branch '8.x.x' into feat/add-opentelemetry-mode-option
adinauer Dec 19, 2024
cb4ede3
Merge branch 'feat/add-opentelemetry-mode-option' into feat/otel-mode…
adinauer Dec 20, 2024
46930d1
use initForTest
adinauer Dec 20, 2024
b2e8e80
Merge branch 'feat/otel-mode-off' into feat/otel-span-strongref
adinauer Dec 20, 2024
8833fc9
use initForTest
adinauer Dec 20, 2024
11bff06
Merge branch 'feat/otel-span-strongref' into feat/agentless-spring-mo…
adinauer Dec 20, 2024
7a1d3b7
Merge branch '8.x.x' into feat/agentless-spring-module
adinauer Dec 20, 2024
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
1 change: 1 addition & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ targets:
maven:io.sentry:sentry-opentelemetry-agentcustomization:
maven:io.sentry:sentry-opentelemetry-core:
# maven:io.sentry:sentry-opentelemetry-agentless:
# maven:io.sentry:sentry-opentelemetry-agentless-spring:
maven:io.sentry:sentry-apollo:
maven:io.sentry:sentry-jdbc:
maven:io.sentry:sentry-graphql:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ body:
- sentry-kotlin-extensions
- sentry-opentelemetry-agent
- sentry-opentelemetry-agentless
- sentry-opentelemetry-agentless-spring
- sentry-opentelemetry-core
- sentry-servlet
- sentry-servlet-jakarta
Expand Down
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@

### Features

- Add `sentry-opentelemetry-agentless-spring` module ([#4000](https://github.com/getsentry/sentry-java/pull/4000))
- This module can be added as a dependency when using Sentry with OpenTelemetry and Spring Boot but don't want to use our Agent. It takes care of configuring OpenTelemetry for use with Sentry.
- You may want to set `OTEL_LOGS_EXPORTER=none;OTEL_METRICS_EXPORTER=none;OTEL_TRACES_EXPORTER=none` env vars to not have the log flooded with error messages regarding OpenTelemetry features we don't use.
- Add `sentry-opentelemetry-agentless` module ([#3961](https://github.com/getsentry/sentry-java/pull/3961))
- This module can be added as a dependency when using Sentry with OpenTelemetry but don't want to use our Agent. It takes care of configuring OpenTelemetry for use with Sentry.
- To enable the auto configuration of it, please set `-Dotel.java.global-autoconfigure.enabled=true` on the `java` command, when starting your application.
- You may also want to set `OTEL_LOGS_EXPORTER=none;OTEL_METRICS_EXPORTER=none;OTEL_TRACES_EXPORTER=none` env vars to not have the log flooded with error messages regarding OpenTelemetry features we don't use.
- `OpenTelemetryUtil.applyOpenTelemetryOptions` now takes an enum instead of a boolean for its mode
- Use `AGENT` when using `sentry-opentelemetry-agent`
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`
- Add `openTelemetryMode` option ([#3994](https://github.com/getsentry/sentry-java/pull/3994))
- It defaults to `AUTO` meaning the SDK will figure out how to best configure itself for use with OpenTelemetry
- Use of OpenTelemetry can also be disabled completely by setting it to `OFF` ([#3995](https://github.com/getsentry/sentry-java/pull/3995))
- In this case even if OpenTelemetry is present, the Sentry SDK will not use it
- Use `AGENT` when using `sentry-opentelemetry-agent`
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`

### Fixes

- Replace deprecated `SimpleInstrumentation` with `SimplePerformantInstrumentation` for graphql 22 ([#3974](https://github.com/getsentry/sentry-java/pull/3974))
- Cache requests for Spring using Springs `ContentCachingRequestWrapper` instead of our own Wrapper to also cache parameters ([#3641](https://github.com/getsentry/sentry-java/pull/3641))
- Previously only the body was cached which could lead to problems in the FilterChain as Request parameters were not available
- We now hold a strong reference to the underlying OpenTelemetry span when it is created through Sentry API ([#3997](https://github.com/getsentry/sentry-java/pull/3997))
- This keeps it from being garbage collected too early

## 8.0.0-rc.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.sentry.SendFireAndForgetEnvelopeSender;
import io.sentry.SendFireAndForgetOutboxSender;
import io.sentry.SentryLevel;
import io.sentry.SentryOpenTelemetryMode;
import io.sentry.android.core.cache.AndroidEnvelopeCache;
import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader;
import io.sentry.android.core.internal.gestures.AndroidViewGestureTargetLocator;
Expand Down Expand Up @@ -101,7 +102,7 @@ static void loadDefaultAndMetadataOptions(
options.setLogger(logger);

options.setDefaultScopeType(ScopeType.CURRENT);

options.setOpenTelemetryMode(SentryOpenTelemetryMode.OFF);
options.setDateProvider(new SentryAndroidDateProvider());

// set a lower flush timeout on Android to avoid ANRs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class EnvelopeFileObserverIntegrationTest {

@AfterTest
fun shutdown() {
Files.delete(file.toPath())
delete(file)
}

private fun delete(f: File) {
f.listFiles()?.forEach { delete(it) }
Files.delete(f.toPath())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
options -> {
options.setEnableExternalConfiguration(true);
options.setInitPriority(InitPriority.HIGH);
OpenTelemetryUtil.applyOpenTelemetryOptions(options, SentryOpenTelemetryMode.AGENT);
options.setOpenTelemetryMode(SentryOpenTelemetryMode.AGENT);
final @Nullable SdkVersion sdkVersion = createSdkVersion(options, versionInfoHolder);
if (sdkVersion != null) {
options.setSdkVersion(sdkVersion);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# sentry-opentelemetry-agentless-spring

*NOTE: Our OpenTelemetry modules are still experimental. Any feedback is welcome.*

## How to use it

Add the latest `sentry-opentelemetry-agentless-spring` module as a dependency and add a `sentry.properties`
configuration file to your project that could look like this:

```properties
# NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard
dsn=https://[email protected]/5428563
traces-sample-rate=1.0
```

For more details on configuring Sentry via `sentry.properties` please see the
[docs page](https://docs.sentry.io/platforms/java/configuration/).

As an alternative to the `SENTRY_PROPERTIES_FILE` environment variable you can provide individual
settings as environment variables (e.g. `SENTRY_DSN=...`) or you may initialize `Sentry` inside
your target application. If you do so, please make sure to apply OpenTelemetry specific options, e.g.
like this:

```
Sentry.init(
options -> {
options.setDsn("...");
...
OpenTelemetryUtil.applyOpenTelemetryOptions(options, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed, as it is now obsolete. I suggest we do that in the #3978 PR

}
)
```

## Getting rid of exporter error messages

In case you are using this module without needing to use any OpenTelemetry exporters you can add
the following environment variables to turn off exporters and stop seeing error messages about
servers not being reachable in the logs.

Example log message:
```
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export spans. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export metrics. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317
```

### Traces

To turn off exporting of traces you can set `OTEL_TRACES_EXPORTER=none`
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters)

### Metrics

To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none`
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
`java-library`
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
api(projects.sentry)
api(projects.sentryOpentelemetry.sentryOpentelemetryBootstrap)
implementation(projects.sentryOpentelemetry.sentryOpentelemetryAgentcustomization)
api(Config.Libs.OpenTelemetry.otelSdk)
api(Config.Libs.OpenTelemetry.otelSemconv)
api(Config.Libs.OpenTelemetry.otelSemconvIncubating)
api(Config.Libs.OpenTelemetry.otelExtensionAutoconfigure)
Comment on lines +14 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we not depending on the sentry-opentelemetry-agentless module because of the AgentlessMarker?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought, it might cause more issues than save work to reuse the other agentless module here since there's very little in both currently.

api(Config.Libs.springBoot3StarterOpenTelemetry)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.sentry.opentelemetry.agent;

public final class AgentlessSpringMarker {}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,58 @@ public final class io/sentry/opentelemetry/OtelSpanFactory : io/sentry/ISpanFact
public fun createTransaction (Lio/sentry/TransactionContext;Lio/sentry/IScopes;Lio/sentry/TransactionOptions;Lio/sentry/TransactionPerformanceCollector;)Lio/sentry/ITransaction;
}

public final class io/sentry/opentelemetry/OtelStrongRefSpanWrapper : io/sentry/opentelemetry/IOtelSpanWrapper {
public fun <init> (Lio/opentelemetry/api/trace/Span;Lio/sentry/opentelemetry/IOtelSpanWrapper;)V
public fun finish ()V
public fun finish (Lio/sentry/SpanStatus;)V
public fun finish (Lio/sentry/SpanStatus;Lio/sentry/SentryDate;)V
public fun getContexts ()Lio/sentry/protocol/Contexts;
public fun getData ()Ljava/util/Map;
public fun getData (Ljava/lang/String;)Ljava/lang/Object;
public fun getDescription ()Ljava/lang/String;
public fun getFinishDate ()Lio/sentry/SentryDate;
public fun getMeasurements ()Ljava/util/Map;
public fun getOperation ()Ljava/lang/String;
public fun getSamplingDecision ()Lio/sentry/TracesSamplingDecision;
public fun getScopes ()Lio/sentry/IScopes;
public fun getSpanContext ()Lio/sentry/SpanContext;
public fun getStartDate ()Lio/sentry/SentryDate;
public fun getStatus ()Lio/sentry/SpanStatus;
public fun getTag (Ljava/lang/String;)Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getThrowable ()Ljava/lang/Throwable;
public fun getTraceId ()Lio/sentry/protocol/SentryId;
public fun getTransactionName ()Ljava/lang/String;
public fun getTransactionNameSource ()Lio/sentry/protocol/TransactionNameSource;
public fun isFinished ()Z
public fun isNoOp ()Z
public fun isProfileSampled ()Ljava/lang/Boolean;
public fun isSampled ()Ljava/lang/Boolean;
public fun makeCurrent ()Lio/sentry/ISentryLifecycleToken;
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
public fun setData (Ljava/lang/String;Ljava/lang/Object;)V
public fun setDescription (Ljava/lang/String;)V
public fun setMeasurement (Ljava/lang/String;Ljava/lang/Number;)V
public fun setMeasurement (Ljava/lang/String;Ljava/lang/Number;Lio/sentry/MeasurementUnit;)V
public fun setOperation (Ljava/lang/String;)V
public fun setStatus (Lio/sentry/SpanStatus;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setThrowable (Ljava/lang/Throwable;)V
public fun setTransactionName (Ljava/lang/String;)V
public fun setTransactionName (Ljava/lang/String;Lio/sentry/protocol/TransactionNameSource;)V
public fun startChild (Lio/sentry/SpanContext;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SentryDate;Lio/sentry/Instrumenter;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SentryDate;Lio/sentry/Instrumenter;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun storeInContext (Lio/opentelemetry/context/Context;)Lio/opentelemetry/context/Context;
public fun toBaggageHeader (Ljava/util/List;)Lio/sentry/BaggageHeader;
public fun toSentryTrace ()Lio/sentry/SentryTraceHeader;
public fun traceContext ()Lio/sentry/TraceContext;
public fun updateEndDate (Lio/sentry/SentryDate;)Z
}

public final class io/sentry/opentelemetry/OtelTransactionSpanForwarder : io/sentry/ITransaction {
public fun <init> (Lio/sentry/opentelemetry/IOtelSpanWrapper;)V
public fun finish ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ public OtelSpanFactory() {
sentrySpan.getSpanContext().setOrigin(spanOptions.getOrigin());
}

return sentrySpan;
if (sentrySpan == null) {
return null;
} else {
return new OtelStrongRefSpanWrapper(otelSpan, sentrySpan);
}
}

private @NotNull Tracer getTracer() {
Expand Down
Loading
Loading