-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove TimeExtractor and use internal API for setting start/end times…
…tamps (#6051) * Remove TimeExtractor and use internal API for setting start/end timestamps * code review comments
- Loading branch information
Mateusz Rzeszutek
authored
May 19, 2022
1 parent
a2a8c11
commit 512a040
Showing
34 changed files
with
244 additions
and
415 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
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
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
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
71 changes: 71 additions & 0 deletions
71
...ion-api/src/main/java/io/opentelemetry/instrumentation/api/internal/InstrumenterUtil.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,71 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.internal; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.time.Instant; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class InstrumenterUtil { | ||
|
||
private static final Logger logger = Logger.getLogger(InstrumenterUtil.class.getName()); | ||
|
||
private static final Method startAndEndMethod; | ||
|
||
static { | ||
Method method = null; | ||
try { | ||
method = | ||
Instrumenter.class.getDeclaredMethod( | ||
"startAndEnd", | ||
Context.class, | ||
Object.class, | ||
Object.class, | ||
Throwable.class, | ||
Instant.class, | ||
Instant.class); | ||
method.setAccessible(true); | ||
} catch (NoSuchMethodException e) { | ||
logger.log( | ||
Level.WARNING, "Could not get Instrumenter#startAndEnd() method with reflection", e); | ||
} | ||
startAndEndMethod = method; | ||
} | ||
|
||
public static <REQUEST, RESPONSE> Context startAndEnd( | ||
Instrumenter<REQUEST, RESPONSE> instrumenter, | ||
Context parentContext, | ||
REQUEST request, | ||
@Nullable RESPONSE response, | ||
@Nullable Throwable error, | ||
Instant startTime, | ||
Instant endTime) { | ||
|
||
if (startAndEndMethod == null) { | ||
// already logged a warning when this class initialized | ||
return parentContext; | ||
} | ||
try { | ||
return (Context) | ||
startAndEndMethod.invoke( | ||
instrumenter, parentContext, request, response, error, startTime, endTime); | ||
} catch (InvocationTargetException | IllegalAccessException e) { | ||
logger.log(Level.WARNING, "Error occurred when calling Instrumenter#startAndEnd()", e); | ||
return parentContext; | ||
} | ||
} | ||
|
||
private InstrumenterUtil() {} | ||
} |
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
Oops, something went wrong.