Skip to content

Commit aacd04e

Browse files
author
Matt Whelan
committed
PR Feedback
README code streamlining, unnesting try blocks, exception error message.
1 parent 0cde221 commit aacd04e

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,7 @@ dependencies {
6262
#### Example Usage
6363

6464
```java
65-
package com.handler.example;
66-
67-
import com.amazonaws.services.lambda.runtime.Context;
68-
import com.amazonaws.services.lambda.runtime.RequestHandler;
69-
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
70-
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
71-
import com.newrelic.opentracing.LambdaTracer;
72-
import com.newrelic.opentracing.aws.LambdaTracing;
73-
import io.opentracing.util.GlobalTracer;
74-
75-
import java.util.Map;
76-
77-
public static class YourLambdaHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
65+
public class YourLambdaHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
7866
static {
7967
// Obtain an instance of the OpenTracing Tracer of your choice
8068
Tracer tracer = LambdaTracer.INSTANCE;

src/main/java/com/newrelic/opentracing/aws/LambdaTracing.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ public Output instrumentRequest(
5252

5353
Span span = buildRootSpan(input, context, tracer, spanContext);
5454
try (Scope scope = tracer.activateSpan(span)) {
55-
try {
56-
Output output = realHandler.apply(input, context);
57-
parseResponse(span, output);
58-
return output;
59-
} catch (Throwable throwable) {
60-
span.log(SpanUtil.createErrorAttributes(throwable));
61-
throw throwable;
62-
}
55+
Output output = realHandler.apply(input, context);
56+
parseResponse(span, output);
57+
return output;
58+
} catch (Throwable throwable) {
59+
span.log(SpanUtil.createErrorAttributes(throwable));
60+
throw throwable;
6361
} finally {
6462
span.finish();
6563
}

src/main/java/com/newrelic/opentracing/aws/StreamLambdaTracing.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ public void instrumentRequest(
4848

4949
Span span = buildRootSpan(input, context, tracer, spanContext);
5050
try (Scope scope = tracer.activateSpan(span)) {
51-
try {
52-
realHandler.handleRequest(input, output, context);
53-
} catch (Throwable throwable) {
54-
span.log(SpanUtil.createErrorAttributes(throwable));
55-
throw throwable;
56-
}
51+
realHandler.handleRequest(input, output, context);
52+
} catch (Throwable throwable) {
53+
span.log(SpanUtil.createErrorAttributes(throwable));
54+
throw throwable;
5755
} finally {
5856
span.finish();
5957
}

src/main/java/com/newrelic/opentracing/aws/TracingRequestStreamHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ default void handleRequest(InputStream input, OutputStream output, Context conte
4141
try {
4242
StreamLambdaTracing.instrument(input, output, context, this::doHandleRequest);
4343
} catch (IOException e) {
44-
throw new RuntimeException(e);
44+
throw new RuntimeException("Exception while processing Lambda invocation", e);
4545
}
4646
}
4747

0 commit comments

Comments
 (0)