-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force flush after finishing lambda function. (#1204)
* Force span flush after lambda invocation. * Force flush after finishing lambda function. * bleh * Better revert * Accessor * OpenTelemetrySdkAccess
- Loading branch information
Anuraag Agrawal
authored
Sep 17, 2020
1 parent
d952354
commit 9635a5e
Showing
8 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
auto-api/src/main/java/io/opentelemetry/instrumentation/auto/api/OpenTelemetrySdkAccess.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,58 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 io.opentelemetry.instrumentation.auto.api; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* A helper to facilitate accessing OpenTelemetry SDK methods from instrumentation. Because | ||
* instrumentation runs in the app classloader, they do not have access to our SDK in the agent | ||
* classloader. So we use this class in the bootstrap classloader to bridge between the two - the | ||
* agent classloader will register implementations of needed SDK functions that can be called from | ||
* instrumentation. | ||
*/ | ||
public class OpenTelemetrySdkAccess { | ||
|
||
/** | ||
* Interface matching {@link io.opentelemetry.sdk.trace.TracerSdkProvider#forceFlush()} to allow | ||
* holding a reference to it. | ||
*/ | ||
public interface ForceFlusher { | ||
/** Executes force flush. */ | ||
void run(int timeout, TimeUnit unit); | ||
} | ||
|
||
private static volatile ForceFlusher FORCE_FLUSH; | ||
|
||
/** Forces flush of pending spans and metrics. */ | ||
public static void forceFlush(int timeout, TimeUnit unit) { | ||
FORCE_FLUSH.run(timeout, unit); | ||
} | ||
|
||
/** | ||
* Sets the {@link Runnable} to execute when instrumentation needs to force flush. This is called | ||
* from the agent classloader to execute the SDK's force flush mechanism. Instrumentation must not | ||
* call this. | ||
*/ | ||
public static void internalSetForceFlush(ForceFlusher forceFlush) { | ||
if (FORCE_FLUSH != null) { | ||
// Only possible by misuse of this API, just ignore. | ||
return; | ||
} | ||
FORCE_FLUSH = forceFlush; | ||
} | ||
} |
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
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