Skip to content

Commit

Permalink
Tag spans with version info, add release script (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhinsch authored Apr 23, 2021
1 parent a8b3ccb commit 42c4a21
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
5 changes: 2 additions & 3 deletions internal/metrics/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import (

"github.com/DataDog/datadog-go/statsd"
"github.com/DataDog/datadog-lambda-go/internal/logger"
"github.com/DataDog/datadog-lambda-go/internal/version"
)

const datadogLambdaVersion = "v0.9.2"

type (
// Listener implements wrapper.HandlerListener, injecting metrics into the context
Listener struct {
Expand Down Expand Up @@ -231,7 +230,7 @@ func getEnhancedMetricsTags(ctx context.Context) []string {
memorySize := fmt.Sprintf("memorysize:%d", lambdacontext.MemoryLimitInMB)
coldStart := fmt.Sprintf("cold_start:%t", isColdStart.(bool))
resource := fmt.Sprintf("resource:%s", lambdacontext.FunctionName)
datadogLambda := fmt.Sprintf("datadog_lambda:%s", datadogLambdaVersion)
datadogLambda := fmt.Sprintf("datadog_lambda:v%s", version.DDLambdaVersion)

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

Expand Down
5 changes: 3 additions & 2 deletions internal/metrics/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/DataDog/datadog-lambda-go/internal/logger"
"github.com/DataDog/datadog-lambda-go/internal/version"
"github.com/aws/aws-lambda-go/lambdacontext"

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

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})
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})
}

func TestGetEnhancedMetricsTagsWithAlias(t *testing.T) {
Expand All @@ -119,7 +120,7 @@ func TestGetEnhancedMetricsTagsWithAlias(t *testing.T) {
}

tags := getEnhancedMetricsTags((lambdacontext.NewContext(ctx, lc)))
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})
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})
}

func TestGetEnhancedMetricsTagsNoLambdaContext(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions internal/trace/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"

"github.com/DataDog/datadog-lambda-go/internal/logger"
"github.com/DataDog/datadog-lambda-go/internal/version"
"github.com/aws/aws-lambda-go/lambdacontext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
Expand Down Expand Up @@ -113,6 +114,8 @@ func startFunctionExecutionSpan(ctx context.Context, mergeXrayTraces bool) trace
tracer.Tag("function_version", functionVersion),
tracer.Tag("request_id", lambdaCtx.AwsRequestID),
tracer.Tag("resource_names", lambdacontext.FunctionName),
tracer.Tag("datadog_lambda", version.DDLambdaVersion),
tracer.Tag("dd_trace", version.DDTraceVersion),
)

if parentSpanContext != nil && mergeXrayTraces {
Expand Down
11 changes: 11 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Do not modify this file manually. It is modified by the release script.
package version

// DDLambdaVersion is the current version number of this library (datadog-lambda-go).
// It is automatically updated by the release script.
const DDLambdaVersion = "0.10.0"

// DDTraceVersion is the version of dd-trace-go required by this libary.
// This should match the version number specified in go.mod.
// It is automatically updated by the release script
const DDTraceVersion = "1.30.0"
68 changes: 68 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Run from the root directory.
# Use with `./release.sh <DESIRED_NEW_VERSION>`

set -e

# Ensure on main, and pull the latest
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ $BRANCH != "main" ]; then
echo "Not on main, aborting"
exit 1
else
echo "Updating main"
git pull origin main
fi

# Ensure no uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "Detected uncommitted changes, aborting"
exit 1
fi

# Check that the new desired version number was specified correctly
if [ -z "$1" ]; then
echo "Must specify a desired version number"
exit 1
elif [[ ! $1 =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Must use a semantic version, e.g., 3.1.4"
exit 1
else
NEW_VERSION=$1
fi

CURRENT_DD_TRACE_VERSION="$(grep "const DDTraceVersion" internal/version/version.go | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
NEW_DD_TRACE_VERSION="$(grep "dd-trace-go.v1" go.mod | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
if [ "$CURRENT_DD_TRACE_VERSION" != "$NEW_DD_TRACE_VERSION" ]; then
read -p "Confirm updating dd-trace-go version from $CURRENT_DD_TRACE_VERSION to $NEW_DD_TRACE_VERSION (y/n)?" CONT
if [ "$CONT" != "y" ]; then
echo "Exiting"
exit 1
fi
fi

CURRENT_VERSION="$(grep "const DDLambdaVersion" internal/version/version.go | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+")"
read -p "Ready to update the library version from $CURRENT_VERSION to $NEW_VERSION and release the library (y/n)?" CONT
if [ "$CONT" != "y" ]; then
echo "Exiting"
exit 1
fi

# Replace version numbers in version.go
sed -E -i '' "s/(DDLambdaVersion = \")[0-9]+\.[0-9]+\.[0-9]+/\1$NEW_VERSION/g" internal/version/version.go
sed -E -i '' "s/(DDTraceVersion = \")[0-9]+\.[0-9]+\.[0-9]+/\1$NEW_DD_TRACE_VERSION/g" internal/version/version.go

# # Commit change
git commit internal/version/version.go -m "Bump version to ${NEW_VERSION}"
git push origin main

# # Tag new release
git tag "v$NEW_VERSION"
git push origin "refs/tags/v$NEW_VERSION"

echo
echo "Now create a new release with the tag v${NEW_VERSION}"
echo "https://github.com/DataDog/datadog-lambda-go/releases/new?tag=v$NEW_VERSION&title=v$NEW_VERSION"


0 comments on commit 42c4a21

Please sign in to comment.