-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathtemplate.yaml
107 lines (101 loc) · 4.4 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: New Relic Example OpenTelemetry Java Lambda Function
Parameters:
newRelicLicenseKey:
Type: String
Description: A New Relic license key.
newRelicEndpoint:
Type: String
Description: New Relic OpenTelemetry endpoint to use.
Default: https://otlp.nr-data.net
Resources:
api:
Type: AWS::Serverless::Api
Properties:
OpenApiVersion: 3.0.2
StageName: api
# This enables AWS X-Ray tracing within API Gateway which is necessary for
# propagating a trace context downstream
TracingEnabled: true
function:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ExampleFunction
Description: New Relic Example OpenTelemetry Java Lambda Function
Environment:
Variables:
# This is equivalent to New Relic's handler wrapper method. It automatically
# wraps the function with OpenTelemetry. It is only used if X-Ray tracing is
# enabled.
AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-handler
DYNAMODB_TABLE: {"Ref": "table"}
# These values get plugged into the collector.yaml file, which is the
# OpenTelemetry Collector's config.
NEW_RELIC_LICENSE_KEY: !Ref newRelicLicenseKey
NEW_RELIC_OPENTELEMETRY_ENDPOINT: !Ref newRelicEndpoint
# This overrides the default location for the OpenTelemetry Collector config
# file, which is /opt/config.yaml by default. This points to the
# collector.yaml in the src directory, which gets deployed along with the
# function itself.
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: /var/task/collector.yaml
# You can suppress agent instrumentation of specific libraries by using
# -Dotel.instrumentation.[name].enabled=false
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/suppressing-instrumentation.md
# Example...
# JAVA_TOOL_OPTIONS: -Dotel.instrumentation.[name].enabled=false
# Set to true to allow debug logs of OTEL Java Agent
JAVA_TOOL_OPTIONS: -Dotel.javaagent.debug=false
OTEL_LOGS_EXPORTER: otlp
OTEL_METRICS_EXPORTER: otlp
Events:
Example:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Method: GET
Path: /
RestApiId: !Ref api
FunctionName: newrelic-example-opentelemetry-lambda-java
Handler: example.App::handleRequest
Layers:
# This is a layer managed by AWS that provides the OpenTelemetry SDK, a modified
# version of the OpenTelemetry Lambda Extension (AWS' version is called ADOT),
# and an auto instrumentation helper (referenced above).
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:901920570463:layer:aws-otel-java-agent-amd64-ver-1-10-1:1
MemorySize: 1024
Policies:
- AWSLambdaBasicExecutionRole
- AWSLambda_ReadOnlyAccess
- AWSXrayWriteOnlyAccess
- AmazonS3ReadOnlyAccess
- AmazonDynamoDBFullAccess
Runtime: java11
Timeout: 300
# This is required to enable additional AWS X-Ray tracing within AWS Distro. We
# export these traces to New Relic instead of writing them to AWS X-Ray.
Tracing: Active
logs:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: {"Fn::Join": ["", ["/aws/lambda/", {"Ref": "function"}]]}
# We override log retention since by default there is no retention limit which
# is both wasteful and expensive. This log group gets created by AWS Lambda
# automatically, so we need to explicitly create it ourselves to ensure a sensible
# retention period.
RetentionInDays: 7
table:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: ip
AttributeType: S
KeySchema:
- AttributeName: ip
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Outputs:
apiEndpoint:
Description: API Endpoint
Value: !Sub "https://${api}.execute-api.${AWS::Region}.amazonaws.com/api/"