Skip to content

Commit 42c4a21

Browse files
authored
Tag spans with version info, add release script (#70)
1 parent a8b3ccb commit 42c4a21

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

internal/metrics/listener.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import (
2222

2323
"github.com/DataDog/datadog-go/statsd"
2424
"github.com/DataDog/datadog-lambda-go/internal/logger"
25+
"github.com/DataDog/datadog-lambda-go/internal/version"
2526
)
2627

27-
const datadogLambdaVersion = "v0.9.2"
28-
2928
type (
3029
// Listener implements wrapper.HandlerListener, injecting metrics into the context
3130
Listener struct {
@@ -231,7 +230,7 @@ func getEnhancedMetricsTags(ctx context.Context) []string {
231230
memorySize := fmt.Sprintf("memorysize:%d", lambdacontext.MemoryLimitInMB)
232231
coldStart := fmt.Sprintf("cold_start:%t", isColdStart.(bool))
233232
resource := fmt.Sprintf("resource:%s", lambdacontext.FunctionName)
234-
datadogLambda := fmt.Sprintf("datadog_lambda:%s", datadogLambdaVersion)
233+
datadogLambda := fmt.Sprintf("datadog_lambda:v%s", version.DDLambdaVersion)
235234

236235
tags := []string{functionName, region, accountId, memorySize, coldStart, datadogLambda}
237236

internal/metrics/listener_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/DataDog/datadog-lambda-go/internal/logger"
24+
"github.com/DataDog/datadog-lambda-go/internal/version"
2425
"github.com/aws/aws-lambda-go/lambdacontext"
2526

2627
"github.com/stretchr/testify/assert"
@@ -105,7 +106,7 @@ func TestGetEnhancedMetricsTags(t *testing.T) {
105106
}
106107
tags := getEnhancedMetricsTags(lambdacontext.NewContext(ctx, lc))
107108

108-
assert.ElementsMatch(t, tags, []string{"functionname:go-lambda-test", "region:us-east-1", "memorysize:256", "cold_start:false", "account_id:123497558138", "resource:go-lambda-test:Latest", "datadog_lambda:" + datadogLambdaVersion})
109+
assert.ElementsMatch(t, tags, []string{"functionname:go-lambda-test", "region:us-east-1", "memorysize:256", "cold_start:false", "account_id:123497558138", "resource:go-lambda-test:Latest", "datadog_lambda:v" + version.DDLambdaVersion})
109110
}
110111

111112
func TestGetEnhancedMetricsTagsWithAlias(t *testing.T) {
@@ -119,7 +120,7 @@ func TestGetEnhancedMetricsTagsWithAlias(t *testing.T) {
119120
}
120121

121122
tags := getEnhancedMetricsTags((lambdacontext.NewContext(ctx, lc)))
122-
assert.ElementsMatch(t, tags, []string{"functionname:go-lambda-test", "region:us-east-1", "memorysize:256", "cold_start:false", "account_id:123497558138", "resource:go-lambda-test:my-alias", "executedversion:1", "datadog_lambda:" + datadogLambdaVersion})
123+
assert.ElementsMatch(t, tags, []string{"functionname:go-lambda-test", "region:us-east-1", "memorysize:256", "cold_start:false", "account_id:123497558138", "resource:go-lambda-test:my-alias", "executedversion:1", "datadog_lambda:v" + version.DDLambdaVersion})
123124
}
124125

125126
func TestGetEnhancedMetricsTagsNoLambdaContext(t *testing.T) {

internal/trace/listener.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616

1717
"github.com/DataDog/datadog-lambda-go/internal/logger"
18+
"github.com/DataDog/datadog-lambda-go/internal/version"
1819
"github.com/aws/aws-lambda-go/lambdacontext"
1920
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
2021
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
@@ -113,6 +114,8 @@ func startFunctionExecutionSpan(ctx context.Context, mergeXrayTraces bool) trace
113114
tracer.Tag("function_version", functionVersion),
114115
tracer.Tag("request_id", lambdaCtx.AwsRequestID),
115116
tracer.Tag("resource_names", lambdacontext.FunctionName),
117+
tracer.Tag("datadog_lambda", version.DDLambdaVersion),
118+
tracer.Tag("dd_trace", version.DDTraceVersion),
116119
)
117120

118121
if parentSpanContext != nil && mergeXrayTraces {

internal/version/version.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Do not modify this file manually. It is modified by the release script.
2+
package version
3+
4+
// DDLambdaVersion is the current version number of this library (datadog-lambda-go).
5+
// It is automatically updated by the release script.
6+
const DDLambdaVersion = "0.10.0"
7+
8+
// DDTraceVersion is the version of dd-trace-go required by this libary.
9+
// This should match the version number specified in go.mod.
10+
// It is automatically updated by the release script
11+
const DDTraceVersion = "1.30.0"

scripts/release.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# Run from the root directory.
4+
# Use with `./release.sh <DESIRED_NEW_VERSION>`
5+
6+
set -e
7+
8+
# Ensure on main, and pull the latest
9+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
10+
if [ $BRANCH != "main" ]; then
11+
echo "Not on main, aborting"
12+
exit 1
13+
else
14+
echo "Updating main"
15+
git pull origin main
16+
fi
17+
18+
# Ensure no uncommitted changes
19+
if [ -n "$(git status --porcelain)" ]; then
20+
echo "Detected uncommitted changes, aborting"
21+
exit 1
22+
fi
23+
24+
# Check that the new desired version number was specified correctly
25+
if [ -z "$1" ]; then
26+
echo "Must specify a desired version number"
27+
exit 1
28+
elif [[ ! $1 =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
29+
echo "Must use a semantic version, e.g., 3.1.4"
30+
exit 1
31+
else
32+
NEW_VERSION=$1
33+
fi
34+
35+
CURRENT_DD_TRACE_VERSION="$(grep "const DDTraceVersion" internal/version/version.go | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
36+
NEW_DD_TRACE_VERSION="$(grep "dd-trace-go.v1" go.mod | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
37+
if [ "$CURRENT_DD_TRACE_VERSION" != "$NEW_DD_TRACE_VERSION" ]; then
38+
read -p "Confirm updating dd-trace-go version from $CURRENT_DD_TRACE_VERSION to $NEW_DD_TRACE_VERSION (y/n)?" CONT
39+
if [ "$CONT" != "y" ]; then
40+
echo "Exiting"
41+
exit 1
42+
fi
43+
fi
44+
45+
CURRENT_VERSION="$(grep "const DDLambdaVersion" internal/version/version.go | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
46+
read -p "Ready to update the library version from $CURRENT_VERSION to $NEW_VERSION and release the library (y/n)?" CONT
47+
if [ "$CONT" != "y" ]; then
48+
echo "Exiting"
49+
exit 1
50+
fi
51+
52+
# Replace version numbers in version.go
53+
sed -E -i '' "s/(DDLambdaVersion = \")[0-9]+\.[0-9]+\.[0-9]+/\1$NEW_VERSION/g" internal/version/version.go
54+
sed -E -i '' "s/(DDTraceVersion = \")[0-9]+\.[0-9]+\.[0-9]+/\1$NEW_DD_TRACE_VERSION/g" internal/version/version.go
55+
56+
# # Commit change
57+
git commit internal/version/version.go -m "Bump version to ${NEW_VERSION}"
58+
git push origin main
59+
60+
# # Tag new release
61+
git tag "v$NEW_VERSION"
62+
git push origin "refs/tags/v$NEW_VERSION"
63+
64+
echo
65+
echo "Now create a new release with the tag v${NEW_VERSION}"
66+
echo "https://github.com/DataDog/datadog-lambda-go/releases/new?tag=v$NEW_VERSION&title=v$NEW_VERSION"
67+
68+

0 commit comments

Comments
 (0)