-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes async instrumentation of v1 sdk
- Loading branch information
Showing
12 changed files
with
298 additions
and
174 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
49 changes: 49 additions & 0 deletions
49
.../java/com/agent/instrumentation/awsjavasdk1/services/lambda/TokenLinkingAsyncHandler.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,49 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.agent.instrumentation.awsjavasdk1.services.lambda; | ||
|
||
import com.amazonaws.handlers.AsyncHandler; | ||
import com.amazonaws.services.lambda.model.InvokeRequest; | ||
import com.amazonaws.services.lambda.model.InvokeResult; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
public class TokenLinkingAsyncHandler implements AsyncHandler<InvokeRequest, InvokeResult> { | ||
|
||
private final AsyncHandler<InvokeRequest, InvokeResult> delegate; | ||
|
||
private Token token; | ||
|
||
public TokenLinkingAsyncHandler(AsyncHandler<InvokeRequest, InvokeResult> delegate) { | ||
this.delegate = delegate; | ||
token = NewRelic.getAgent().getTransaction().getToken(); | ||
} | ||
|
||
@Override | ||
@Trace(async = true) | ||
public void onError(Exception e) { | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Java", delegate.getClass().getName(), "onError"); | ||
delegate.onError(e); | ||
} | ||
|
||
@Override | ||
@Trace(async = true) | ||
public void onSuccess(InvokeRequest request, InvokeResult invokeResult) { | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Java", delegate.getClass().getName(), "onSuccess"); | ||
delegate.onSuccess(request, invokeResult); | ||
} | ||
} |
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
Oops, something went wrong.