-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added SchedulerListener Instrumentation for Scheduler-level errors in Quartz #19117
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
Open
angad-2
wants to merge
24
commits into
open-telemetry:main
Choose a base branch
from
angad-2:main-angad
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1f43834
added quartz scheduler listener instrumentation for scheduler errors
angad-2 cb5f693
added quartz.scheduler.error.message, populated from request.getMessa…
angad-2 9928f89
added scheduler error in the other test methods and the success and f…
angad-2 5fdd6a8
swicthed to emitting an event via logs api
angad-2 17e6fa1
applied formatting to test
angad-2 239d543
swicthed to setEventName
angad-2 715ef69
moved error message into the log body
angad-2 b1c00ca
added quartz scheduler name to job execution spans, added setExceptio…
angad-2 87c54c5
fixed empty catch block
angad-2 afca3f9
suppress scheduler error only during job execution via context marker
angad-2 26ca9f4
extracted listener checks, used exact attribute assertions
angad-2 c39a338
renamed experimental config to emit-experimental-telemetry, deprecate…
angad-2 6f229b0
Address review comments from copilot-pull-request-reviewer: test sche…
trask ed4606a
Address review comment from copilot-pull-request-reviewer: document d…
trask 9cfeaed
Address review comments from copilot-pull-request-reviewer: document …
trask 375b45d
Merge branch 'main' into main-angad
trask 1c051f6
Address review comment from copilot-pull-request-reviewer: document Q…
trask c03dec1
Address review comment from copilot-pull-request-reviewer: preserve d…
trask daf9675
Address review comment from copilot-pull-request-reviewer: gate sched…
trask a6401da
address review comment from copilot-pull-request-reviewer: suppress o…
angad-2 3e795a2
Fix Quartz scheduler error regression test
trask b67cd69
Merge remote-tracking branch 'upstream/main' into main-angad
trask 9758f71
fix: apply spotless formatting and align README table
angad-2 ab9f715
Merge branch 'main' into main-angad
angad-2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
....0/library/src/main/java/io/opentelemetry/instrumentation/quartz/v2_0/SchedulerError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.quartz.v2_0; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * A scheduler-level error reported by Quartz through {@code SchedulerListener.schedulerError}. This | ||
| * is the "request" object that drives the scheduler-error {@link | ||
| * io.opentelemetry.instrumentation.api.instrumenter.Instrumenter}. | ||
| */ | ||
| final class SchedulerError { | ||
|
|
||
| private final String schedulerName; | ||
| @Nullable private final String message; | ||
|
|
||
| SchedulerError(String schedulerName, @Nullable String message) { | ||
| this.schedulerName = schedulerName; | ||
| this.message = message; | ||
| } | ||
|
|
||
| String getSchedulerName() { | ||
| return schedulerName; | ||
| } | ||
|
|
||
| @Nullable | ||
| String getMessage() { | ||
| return message; | ||
| } | ||
|
angad-2 marked this conversation as resolved.
Outdated
|
||
| } | ||
32 changes: 32 additions & 0 deletions
32
.../java/io/opentelemetry/instrumentation/quartz/v2_0/SchedulerErrorAttributesExtractor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.quartz.v2_0; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| final class SchedulerErrorAttributesExtractor implements AttributesExtractor<SchedulerError, Void> { | ||
|
|
||
| // Experimental attribute: name/shape may change until scheduler instrumentation stabilizes. | ||
| private static final AttributeKey<String> SCHEDULER_NAME = | ||
| AttributeKey.stringKey("quartz.scheduler.name"); | ||
|
|
||
| @Override | ||
| public void onStart(AttributesBuilder attributes, Context parentContext, SchedulerError request) { | ||
| attributes.put(SCHEDULER_NAME, request.getSchedulerName()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onEnd( | ||
| AttributesBuilder attributes, | ||
| Context context, | ||
| SchedulerError request, | ||
| @Nullable Void response, | ||
| @Nullable Throwable error) {} | ||
| } |
52 changes: 52 additions & 0 deletions
52
.../src/main/java/io/opentelemetry/instrumentation/quartz/v2_0/TracingSchedulerListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.quartz.v2_0; | ||
|
|
||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
| import org.quartz.SchedulerException; | ||
| import org.quartz.listeners.SchedulerListenerSupport; | ||
|
|
||
| /** | ||
| * Instruments scheduler-level Quartz events. Extends {@link SchedulerListenerSupport} so we only | ||
| * override the hooks we care about; every other {@code SchedulerListener} method defaults to a | ||
| * no-op and is available as an extension point for future events. | ||
| */ | ||
| final class TracingSchedulerListener extends SchedulerListenerSupport { | ||
|
|
||
| private final Instrumenter<SchedulerError, Void> instrumenter; | ||
| private final String schedulerName; | ||
|
|
||
| TracingSchedulerListener(Instrumenter<SchedulerError, Void> instrumenter, String schedulerName) { | ||
| this.instrumenter = instrumenter; | ||
| this.schedulerName = schedulerName; | ||
| } | ||
|
|
||
| @Override | ||
| public void schedulerError(String msg, SchedulerException cause) { | ||
| Context parentContext = Context.current(); | ||
|
|
||
| // Quartz also reports job execution failures through schedulerError, on the same thread while | ||
| // the job execution span is still current. That failure is already recorded on the job span, so | ||
| // emitting another span here would just duplicate it. Only instrument genuine scheduler-level | ||
| // errors, i.e. when no span is currently active. | ||
| if (Span.fromContext(parentContext).getSpanContext().isValid()) { | ||
| return; | ||
|
trask marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| SchedulerError request = new SchedulerError(schedulerName, msg); | ||
| if (!instrumenter.shouldStart(parentContext, request)) { | ||
| return; | ||
| } | ||
|
|
||
| // schedulerError is a point-in-time event with no start/end bracket around work, so we start | ||
|
trask marked this conversation as resolved.
Outdated
|
||
| // and immediately end a span that records the failure. The span has no children but surfaces | ||
| // the scheduler error (and the SchedulerException) in traces. | ||
| Context context = instrumenter.start(parentContext, request); | ||
| instrumenter.end(context, request, null, cause); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.