-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af6fcbf
commit f065ad7
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
56 changes: 56 additions & 0 deletions
56
db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/OtelTracingListener.java
This file contains 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,56 @@ | ||
/* | ||
* Copyright (C) Gustav Karlsson | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.kagkarlsson.scheduler.event; | ||
|
||
import com.github.kagkarlsson.scheduler.CurrentlyExecuting; | ||
import com.github.kagkarlsson.scheduler.task.ExecutionComplete; | ||
import com.github.kagkarlsson.scheduler.task.ExecutionComplete.Result; | ||
import com.github.kagkarlsson.scheduler.task.TaskInstance; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
|
||
public class OtelTracingListener extends AbstractSchedulerListener { | ||
|
||
private final OpenTelemetry openTelemetry; | ||
|
||
public OtelTracingListener(OpenTelemetry openTelemetry) { | ||
this.openTelemetry = openTelemetry; | ||
} | ||
|
||
@Override | ||
public void onExecutionStart(CurrentlyExecuting currentlyExecuting) { | ||
Tracer t = openTelemetry.getTracer("db-scheduler.execution"); | ||
TaskInstance<?> taskInstance = currentlyExecuting.getTaskInstance(); | ||
Span span = | ||
t.spanBuilder("execute") | ||
.setAttribute("task-name", taskInstance.getTaskName()) | ||
.setAttribute("task-instance-id", taskInstance.getId()) | ||
.startSpan(); | ||
span.makeCurrent(); | ||
} | ||
|
||
@Override | ||
public void onExecutionComplete(ExecutionComplete executionComplete) { | ||
Span currentSpan = Span.current(); | ||
|
||
try { | ||
if (executionComplete.getResult() == Result.FAILED) { | ||
executionComplete.getCause().ifPresent(currentSpan::recordException); | ||
} | ||
} finally { | ||
currentSpan.end(); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -94,7 +94,6 @@ | |
<version>3.12.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</dependencyManagement> | ||
|
||
|