Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 52bd050

Browse files
peterdemetianchuskatsutamaxdaykimi-p
authored
Rebase to original repo (#1)
* Create codeql-analysis.yml (DataDog#100) * Create codeql-analysis.yml * Update codeql-analysis.yml * Update run_integration_tests.sh * Do not show error messages even if neither DD_API_KEY nor DD_KMS_API_KEY is set when Lambda Extension is running (DataDog#102) * Bump version to 1.4.0 * Bump go + fasthttp + lint (DataDog#104) * Consolidate serverless configurations into one place (DataDog#105) * Update README.md * Update README.md * Bump dd-trace-go to latest version to address some vulnerabilities (DataDog#109) * Bump dd-trace-go to latest version to address some vulnaribilities * update go.sum with `go mod tidy` * Bump version to 1.6.0 * bump codeql (DataDog#112) * Bump dd-trace-go to v1.41 (DataDog#115) * Bump version to 1.7.0 * [SLS-2330] Add support for universal instrumentation with the extension (DataDog#116) add option to use universal instrumentation * [EEP-444] include error in failed metric send log (DataDog#118) Co-authored-by: Corey Griffin <[email protected]> * [SLS-2492] Upgrade aws sdk v2 (DataDog#113) upgrade sdk * Bump version to 1.8.0 * Use new account in integration tests (DataDog#119) * set the architecture explicitely (DataDog#122) * mask init runtime logs (DataDog#123) * Update libs (DataDog#121) * bump go 1.18 (DataDog#125) * Retry sending trace payloads on failure. (DataDog#128) * Bump version to 1.9.0 * Update DD Trace to v1.51.0(DataDog#133) * Bump go version to 1.20 (DataDog#140) Bump go version to 1.20 * Upgrade version of dd-trace-go to v1.54.1 (DataDog#141) * Bump version to 1.10.0 * Propagate trace context from SQS events (DataDog#142) * Default parent id to be trace id if not found elsewhere. * Look for trace context in context object as well as headers. * Apply trace context before starting the function execution span. * Update signature in tests. * Add spanid of execution span to context. * Do not ignore priority "-128". * Test that default parent id set to trace id. * Test span id added to context. * Test uses trace context from context object. * Bump version to 1.11.0 * feat: automate AppSec enablement setup (e.g: `AWS_LAMBDA_RUNTIME_API`) (DataDog#143) * feat: honor AWS_LAMBDA_EXEC_WRAPPER when AWS Lambda does not In order to simplify onboarding & make it more uniform across languages, inspect the value of the `AWS_LAMBDA_EXEC_WRAPPER` environment variable and apply select environment variable changes it perofrms upon decorating a handler. This is necessary/useful because that environment variable is not honored by custom runtimes (`provided`, `provided.al2`) as well as the `go1.x` runtime (which is a glorified provided runtime). The datadog Lambda wrapper starts a proxy to inject ASM functionality directly on the Lambda runtime API instead of having to manually instrument each and every lambda handler/application, and modifies `AWS_LAMBDA_RUNTIME_API` to instruct Lambda language runtime client libraries to go through it instead of directly interacting with the Lambda control plane. APPSEC-11534 * pivot to a different, cheaper strategy * typo fix * PR feedback * minor fixups * add warning in go1.x runtime if lambda.norpc build tag was not enabled * Bump version to 1.12.0 * Re-add configs after upstream rebase * Bump packages * Remove deprecated `io/ioutil` calls --------- Co-authored-by: Tian Chu <[email protected]> Co-authored-by: Soshi Katsuta <[email protected]> Co-authored-by: Maxime David <[email protected]> Co-authored-by: kimi <[email protected]> Co-authored-by: Kimi Wu <[email protected]> Co-authored-by: Dylan Yang <[email protected]> Co-authored-by: Corey Griffin <[email protected]> Co-authored-by: Corey Griffin <[email protected]> Co-authored-by: Marcin Rabenda <[email protected]> Co-authored-by: Rey Abolofia <[email protected]> Co-authored-by: Rey Abolofia <[email protected]> Co-authored-by: Andrew Rodriguez <[email protected]> Co-authored-by: Ivan Topolcic <[email protected]> Co-authored-by: Romain Marcadier <[email protected]>
1 parent 0e69246 commit 52bd050

38 files changed

+1909
-614
lines changed

.github/workflows/build.yml

+49-55
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,68 @@ jobs:
88

99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v4
1212

1313
- name: Set up Go
14-
uses: actions/setup-go@v2
14+
uses: actions/setup-go@v4
1515
with:
16-
go-version: 1.13
17-
18-
- name: Install Golint
19-
run: go install golang.org/x/lint/golint
20-
21-
- name: Lint
22-
run: golint
16+
go-version: '1.21'
17+
18+
- name: golangci-lint
19+
uses: golangci/golangci-lint-action@v3
2320

2421
unit-test:
2522
runs-on: ubuntu-latest
2623

2724
steps:
2825
- name: Checkout
29-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
3027

3128
- name: Set up Go
32-
uses: actions/setup-go@v1
29+
uses: actions/setup-go@v4
3330
with:
34-
go-version: 1.13
31+
go-version: '1.21'
3532

3633
- name: Run tests
3734
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
3835

39-
- name: Upload code coverage report
40-
run: bash <(curl -s https://codecov.io/bash)
41-
42-
integration-test:
43-
runs-on: ubuntu-latest
44-
45-
steps:
46-
- name: Checkout
47-
uses: actions/checkout@v2
48-
49-
- name: Set up Node 14
50-
uses: actions/setup-node@v1
51-
with:
52-
node-version: 14
53-
54-
- name: Set up Go
55-
uses: actions/setup-go@v1
56-
with:
57-
go-version: 1.13
58-
59-
- name: Cache Node modules
60-
id: cache-node-modules
61-
uses: actions/cache@v2
62-
with:
63-
path: "**/node_modules"
64-
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
65-
66-
- name: Install Serverless Framework
67-
run: sudo yarn global add serverless --prefix /usr/local
68-
69-
- name: Install dependencies
70-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
71-
working-directory: tests/integration_tests/
72-
run: yarn install
73-
74-
- name: Run tests
75-
env:
76-
BUILD_LAYERS: true
77-
DD_API_KEY: ${{ secrets.DD_API_KEY }}
78-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
79-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
80-
working-directory: tests/integration_tests/
81-
run: ./run_integration_tests.sh
36+
# integration-test:
37+
# runs-on: ubuntu-latest
38+
39+
# steps:
40+
# - name: Checkout
41+
# uses: actions/checkout@v4
42+
43+
# - name: Set up Node 14
44+
# uses: actions/setup-node@v3
45+
# with:
46+
# node-version: 14
47+
48+
# - name: Set up Go
49+
# uses: actions/setup-go@v4
50+
# with:
51+
# go-version: '1.21'
52+
53+
# - name: Cache Node modules
54+
# id: cache-node-modules
55+
# uses: actions/cache@v3
56+
# with:
57+
# path: "**/node_modules"
58+
# key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
59+
60+
# - name: Install Serverless Framework
61+
# run: sudo yarn global add serverless --prefix /usr/local
62+
63+
# - name: Install dependencies
64+
# if: steps.cache-node-modules.outputs.cache-hit != 'true'
65+
# working-directory: tests/integration_tests/
66+
# run: yarn install
67+
68+
# - name: Run tests
69+
# env:
70+
# BUILD_LAYERS: true
71+
# DD_API_KEY: ${{ secrets.DD_API_KEY }}
72+
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
73+
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
74+
# working-directory: tests/integration_tests/
75+
# run: ./run_integration_tests.sh

.github/workflows/codeql-analysis.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main, master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '33 8 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'go' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v2
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v2

README.md

+3-96
Original file line numberDiff line numberDiff line change
@@ -10,104 +10,11 @@ Datadog Lambda Library for Go enables enhanced Lambda metrics, distributed traci
1010

1111
## Installation
1212

13-
Follow the installation instructions [here](https://docs.datadoghq.com/serverless/installation/go/).
13+
Follow the [installation instructions](https://docs.datadoghq.com/serverless/installation/go/), and view your function's enhanced metrics, traces and logs in Datadog.
1414

15-
## Enhanced Metrics
15+
## Configurations
1616

17-
Once [installed](#installation), you should be able to view enhanced metrics for your Lambda function in Datadog.
18-
19-
Check out the official documentation on [Datadog Lambda enhanced metrics](https://docs.datadoghq.com/integrations/amazon_lambda/?tab=go#real-time-enhanced-lambda-metrics).
20-
21-
## Custom Metrics
22-
23-
Once [installed](#installation), you should be able to submit custom metrics from your Lambda function.
24-
25-
Check out the instructions for [submitting custom metrics from AWS Lambda functions](https://docs.datadoghq.com/integrations/amazon_lambda/?tab=go#custom-metrics).
26-
27-
## Tracing
28-
29-
Set the `DD_TRACE_ENABLED` environment variable to `true` to enable Datadog tracing. When Datadog tracing is enabled, the library will inject a span representing the Lambda's execution into the context object. You can then use the included `dd-trace-go` package to create additional spans from the context or pass the context to other services. For more information, see the [dd-trace-go documentation](https://godoc.org/gopkg.in/DataDog/dd-trace-go.v1/ddtrace).
30-
31-
```go
32-
import (
33-
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
34-
httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
35-
)
36-
37-
func handleRequest(ctx context.Context, ev events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
38-
// Trace an HTTP request
39-
req, _ := http.NewRequestWithContext(ctx, "GET", "https://www.datadoghq.com", nil)
40-
client := http.Client{}
41-
client = *httptrace.WrapClient(&client)
42-
client.Do(req)
43-
44-
// Create a custom span
45-
s, _ := tracer.StartSpanFromContext(ctx, "child.span")
46-
time.Sleep(100 * time.Millisecond)
47-
s.Finish()
48-
}
49-
```
50-
51-
You can also use the injected span to [connect your logs and traces](https://docs.datadoghq.com/tracing/connect_logs_and_traces/go/).
52-
53-
```go
54-
func handleRequest(ctx context.Context, ev events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
55-
currentSpan, _ := tracer.SpanFromContext(ctx)
56-
log.Printf("my log message %v", currentSpan)
57-
}
58-
```
59-
60-
If you are also using AWS X-Ray to trace your Lambda functions, you can set the `DD_MERGE_XRAY_TRACES` environment variable to `true`, and Datadog will merge your Datadog and X-Ray traces into a single, unified trace.
61-
62-
### Trace Context Extraction
63-
64-
To link your distributed traces, datadog-lambda-go looks for the `x-datadog-trace-id`, `x-datadog-parent-id` and `x-datadog-sampling-priority` trace `headers` in the Lambda event payload.
65-
If the headers are found it will set the parent trace to the trace context extracted from the headers.
66-
67-
It is possible to configure your own trace context extractor function if the default extractor does not support your event.
68-
69-
```go
70-
myExtractorFunc := func(ctx context.Context, ev json.RawMessage) map[string]string {
71-
// extract x-datadog-trace-id, x-datadog-parent-id and x-datadog-sampling-priority.
72-
}
73-
74-
cfg := &ddlambda.Config{
75-
TraceContextExtractor: myExtractorFunc,
76-
}
77-
ddlambda.WrapFunction(handler, cfg)
78-
```
79-
80-
A more complete example can be found in the `ddlambda_example_test.go` file.
81-
82-
## Environment Variables
83-
84-
### DD_FLUSH_TO_LOG
85-
86-
Set to `true` (recommended) to send custom metrics asynchronously (with no added latency to your Lambda function executions) through CloudWatch Logs with the help of [Datadog Forwarder](https://github.com/DataDog/datadog-serverless-functions/tree/master/aws/logs_monitoring). Defaults to `false`. If set to `false`, you also need to set `DD_API_KEY` and `DD_SITE`.
87-
88-
### DD_API_KEY
89-
90-
If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), the Datadog API Key must be defined.
91-
92-
### DD_SITE
93-
94-
If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), you must set `DD_SITE`. Possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com`, `us5.datadoghq.com`, and `ddog-gov.com`. The default is `datadoghq.com`.
95-
96-
### DD_LOG_LEVEL
97-
98-
Set to `debug` enable debug logs from the Datadog Lambda Library. Defaults to `info`.
99-
100-
### DD_ENHANCED_METRICS
101-
102-
Generate enhanced Datadog Lambda integration metrics, such as, `aws.lambda.enhanced.invocations` and `aws.lambda.enhanced.errors`. Defaults to `true`.
103-
104-
### DD_TRACE_ENABLED
105-
106-
Initialize the Datadog tracer when set to `true`. Defaults to `false`.
107-
108-
### DD_MERGE_XRAY_TRACES
109-
110-
If you are using both X-Ray and Datadog tracing, set this to `true` to merge the X-Ray and Datadog traces. Defaults to `false`.
17+
See the [advanced configuration options](https://docs.datadoghq.com/serverless/configuration) to tag your telemetry, capture request/response payloads, filter or scrub sensitive information from logs or traces, and more.
11118

11219
## Opening Issues
11320

awslambdanorpc.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build lambda.norpc
2+
// +build lambda.norpc
3+
4+
/*
5+
* Unless explicitly stated otherwise all files in this repository are licensed
6+
* under the Apache License Version 2.0.
7+
*
8+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
9+
* Copyright 2021 Datadog, Inc.
10+
*/
11+
12+
package ddlambda
13+
14+
const awsLambdaRpcSupport = false

awslambdawithrpc.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build !lambda.norpc
2+
// +build !lambda.norpc
3+
4+
/*
5+
* Unless explicitly stated otherwise all files in this repository are licensed
6+
* under the Apache License Version 2.0.
7+
*
8+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
9+
* Copyright 2021 Datadog, Inc.
10+
*/
11+
12+
package ddlambda
13+
14+
const awsLambdaRpcSupport = true

0 commit comments

Comments
 (0)