Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Add WithLogStartup tracer startup option #861

Closed
eriklarko opened this issue Mar 3, 2021 · 3 comments
Closed

proposal: Add WithLogStartup tracer startup option #861

eriklarko opened this issue Mar 3, 2021 · 3 comments
Labels
proposal/accepted Accepted proposals proposal more in depth change that requires full team approval

Comments

@eriklarko
Copy link
Contributor

Thank you for an amazing library, it has helped me debug issues countless times and has been easy to set up and maintain.

When a tracer starts it prints some information to stdout by default. While this was great during development it isn't as useful to us in production so we'd like a way to suppress it. Luckily we can easily do that with the DD_TRACE_STARTUP_LOGS environment variable as seen here.

However, we configure other aspects of the tracer using tracer.StartOptions and it would be great if we could suppress this log the same way. From my perhaps limited investigation, it appears that gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer.config.logStartup is only set in that one location, so there might be room for a tracer.WithLogStartup(bool) start option, which is exactly what I'm proposing :)

I went ahead and tried to implement it before I read CONTRIBUTING.md, so I'm including a possible solution here. But I should have read the doc first so I'm happy to throw away the tiny amount of work I put into it.

There are other ways to achieve the same result using start options; for example, WithLogger could be used with a custom logger. I'm more than happy to go with an already implemented solution, but it's hard to beat the clarity of a specialized StartOption.

// in ddtrace/tracer/option.go

....

// WithLogStartup allows control over whether to print the startup log or not
func WithLogStartup(logStartup bool) StartOption {
     return func(c *config) {
             c.logStartup = logStartup
     }
}

...
@gbbr
Copy link
Contributor

gbbr commented Mar 4, 2021

Thank you for an amazing library, it has helped me debug issues countless times and has been easy to set up and maintain.

That's really nice to hear 🙂 I will pass this message onto our team internally too!

You can go ahead and make this change if you wish!

@gbbr gbbr added the proposal more in depth change that requires full team approval label Mar 4, 2021
@knusbaum knusbaum added the proposal/accepted Accepted proposals label May 26, 2021
@knusbaum
Copy link
Contributor

Done!

@xrn
Copy link

xrn commented Nov 23, 2021

Hi,

I am a bit lost here. On each lambda start, I am receiving

{
    "date": "2021-11-23T11:22:38Z",
    "os_name": "Linux (Unknown Distribution)",
    "os_version": "2018.03",
    "version": "v1.33.0",
    "lang": "Go",
    "lang_version": "go1.15.4",
    "env": "",
    "service": "aws.lambda",
    "agent_url": "http://localhost:8126/v0.4/traces",
    "agent_error": "",
    "debug": false,
    "analytics_enabled": false,
    "sample_rate": "NaN",
    "sampling_rules": null,
    "sampling_rules_error": "",
    "tags": {
        "_dd.origin": "lambda",
        "runtime-id": "be964b71-8cf5-4458-b03a-d5404b7f5c84"
    },
    "runtime_metrics_enabled": false,
    "health_metrics_enabled": false,
    "dd_version": "",
    "architecture": "amd64",
    "global_service": "aws.lambda",
    "lambda_mode": "true",
    "agent_features": {
        "DropP0s": false,
        "V05": false,
        "Stats": false
    }
}
{
    "m": "aws.lambda.enhanced.invocations",
    "v": 1,
    "e": 1637666558,
    "t": [
        "functionname:MonitorsGet-Lambda",
        "region:us-east-1",
        "account_id:120783238089",
        "memorysize:256",
        "cold_start:true",
        "datadog_lambda:v1.3.0",
        "resource:PROD2-MonitorsGet-Lambda",
        "dd_lambda_layer:datadog-go1.15.4"
    ]
}

I believe this are StartupLogs and I can disable them.

Here is my configuration:

import (
	"context"
	"encoding/json"
	"errors"

	ddlambda "github.com/DataDog/datadog-lambda-go"
	golambda "github.com/aws/aws-lambda-go/lambda"
)

func main() {
	config = &ddlambda.Config{
		DDTraceEnabled:        true,
		MergeXrayTraces:       true,
		ShouldUseLogForwarder: true,
	}

	golambda.Start(ddlambda.WrapHandler(handler, config))
}

And then I am using Xray in my lambdas - for a logger, I am using

func SetUpLogger(ctx context.Context) *logrus.Entry {
	// Create span for lambda
	span, _ := tracer.SpanFromContext(ctx)

	// Set log format
	l := logrus.New()
	l.SetLevel(logrus.InfoLevel)
	l.SetReportCaller(true)
	l.SetFormatter(&logrus.JSONFormatter{})

	return l.WithFields((logrus.Fields{
		"dd.trace_id": span.Context().TraceID(),
		"dd.span_id":  span.Context().SpanID(),
	}))
}

Is there any option in such configuration to disable logs using WithLogStartup ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal/accepted Accepted proposals proposal more in depth change that requires full team approval
Projects
None yet
Development

No branches or pull requests

4 participants