-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
[WIP] fix console samples #3979
base: feat/update-otel-sample-readme
Are you sure you want to change the base?
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
- [WIP] fix console samples ([#3979](https://github.com/getsentry/sentry-java/pull/3979)) If none of the above apply, you can opt out of this check by adding |
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
42a4b98 | 419.52 ms | 468.80 ms | 49.27 ms |
6ebd7bb | 415.76 ms | 489.13 ms | 73.36 ms |
d035e4a | 323.87 ms | 361.86 ms | 37.99 ms |
15316ed | 429.28 ms | 439.04 ms | 9.76 ms |
8902d25 | 383.02 ms | 387.58 ms | 4.56 ms |
617e26e | 466.04 ms | 481.19 ms | 15.15 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
42a4b98 | 1.65 MiB | 2.31 MiB | 676.08 KiB |
6ebd7bb | 1.65 MiB | 2.31 MiB | 677.56 KiB |
d035e4a | 1.65 MiB | 2.31 MiB | 676.08 KiB |
15316ed | 1.65 MiB | 2.31 MiB | 676.08 KiB |
8902d25 | 1.65 MiB | 2.31 MiB | 676.08 KiB |
617e26e | 1.65 MiB | 2.31 MiB | 677.57 KiB |
…-java into fix/fix-console-samples
…ter OTEL AutoInit
final TransactionOptions options = new TransactionOptions(); | ||
options.setBindToScope(true); | ||
ITransaction transaction = Sentry.startTransaction("transaction name", "op", options); |
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.
Binding the transaction to scope is required here for the sample to work as expected as later in the code we have a line Sentry.captureMessage("this message is connected to the outerSpan");
which only works as described if the transaction is on the scope IIRC.
@@ -86,10 +87,10 @@ public static void main(String[] args) throws InterruptedException { | |||
options.setTracesSampler( | |||
context -> { | |||
// only 10% of transactions with "/product" prefix will be collected | |||
if (!context.getTransactionContext().getName().startsWith("/products")) { | |||
if (context.getTransactionContext().getName().startsWith("/products")) { |
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.
Makes the code do what the comment says :)
return 0.1; | ||
} else { | ||
return 0.5; | ||
return 1.0; |
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.
set to 1.0
for all transactions except for /products
to make it easier for people trying this sample
|
||
public class Main { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
final OpenTelemetrySdk sdk = |
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.
AutoConfiguredOpentelemetry
is needed to initialize spi provided classes.
We can make this a little simpler by using setResultAsGlobal()
on the builder:
AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal()
.addPropertiesSupplier(
() -> {
final Map<String, String> properties = new HashMap<>();
properties.put("otel.logs.exporter", "none");
properties.put("otel.metrics.exporter", "none");
properties.put("otel.traces.exporter", "none");
return properties;
})
.build();
📜 Description
Fixes the sentry console samples
💡 Motivation and Context
The
sentry-samples-console-opentelemetry-noagent
sample did not produce any spans.💚 How did you test it?
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps