-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run callbacks in the context of the parent span
- Loading branch information
Showing
3 changed files
with
61 additions
and
8 deletions.
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
44 changes: 44 additions & 0 deletions
44
...n/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbObjetWrapper.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,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.influxdb.v2_4; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
|
||
public final class InfluxDbObjetWrapper { | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Object wrap(Object object, Context parentContext) { | ||
if (object instanceof Consumer) { | ||
return (Consumer<Object>) | ||
o -> { | ||
try (Scope ignore = parentContext.makeCurrent()) { | ||
((Consumer<Object>) object).accept(o); | ||
} | ||
}; | ||
} else if (object instanceof BiConsumer) { | ||
return (BiConsumer<Object, Object>) | ||
(o1, o2) -> { | ||
try (Scope ignore = parentContext.makeCurrent()) { | ||
((BiConsumer<Object, Object>) object).accept(o1, o2); | ||
} | ||
}; | ||
} else if (object instanceof Runnable) { | ||
return (Runnable) | ||
() -> { | ||
try (Scope ignore = parentContext.makeCurrent()) { | ||
((Runnable) object).run(); | ||
} | ||
}; | ||
} | ||
|
||
return object; | ||
} | ||
|
||
private InfluxDbObjetWrapper() {} | ||
} |
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