Code Monkey home page Code Monkey logo

Comments (3)

tianchu avatar tianchu commented on August 30, 2024 2

This plugin is designed to only support Python and Node.js for now (expanding to other runtimes in the future). You do have to add the extension layer on your own for Go Lambda functions.

https://docs.datadoghq.com/serverless/installation/go will be updated soon with instructions for using the Extension.

I can help post a sample application here later today.

from serverless-plugin-datadog.

AkselsLedins avatar AkselsLedins commented on August 30, 2024

Thank you very much @tianchu , I would be very keen to have an example of this plugin with Go and the provided.al2 runtime

from serverless-plugin-datadog.

tianchu avatar tianchu commented on August 30, 2024

Here is the preview version of the doc with updated instructions https://docs-staging.datadoghq.com/tian.chu/lambda-extension-for-go/serverless/installation/go

Sample application:

serverless.yaml

service: test-go-extension

provider:
  name: aws
  region: ap-southeast-1

functions:
  test-go-extension:
    name: test-go-extension
    handler: handler
    runtime: provided.al2
    events:
      - http: GET hello
    environment:
      DD_API_KEY: <redacted>
      DD_ENV: dev
      DD_SERVICE: test-go-extension
      DD_VERSION: 0.0.1
      DD_SERVERLESS_LOGS_ENABLED: true
      DD_TRACE_ENABLED: true

app.go

package main

import (
	"context"
	"time"

	"github.com/aws/aws-lambda-go/lambda"

	ddlambda "github.com/DataDog/datadog-lambda-go"
	"github.com/aws/aws-lambda-go/events"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

type testResponse struct {
	StatusCode int    `json:"statusCode"`
	Body       string `json:"body"`
}

func handleRequest(ctx context.Context, ev events.APIGatewayProxyRequest) (testResponse, error) {

	// submit a custom span
	s, _ := tracer.StartSpanFromContext(ctx, "test.span")
	time.Sleep(100 * time.Millisecond)
	s.Finish()

	ddlambda.Distribution("test.go.metric", 1)

	return testResponse{
		StatusCode: 200,
		Body:       "hello, world",
	}, nil
}

func main() {
	lambda.Start(ddlambda.WrapHandler(handleRequest, nil))
}

Build command

env GOOS=linux go build -ldflags="-s -w" -o handler app.go

from serverless-plugin-datadog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.