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

ddtrace/tracer: diagnostic and startup logs should be in JSON format. #2152

Closed
mariel-sendblocks opened this issue Jul 27, 2023 · 6 comments · Fixed by #2406
Closed

ddtrace/tracer: diagnostic and startup logs should be in JSON format. #2152

mariel-sendblocks opened this issue Jul 27, 2023 · 6 comments · Fixed by #2406
Labels
proposal more in depth change that requires full team approval tracer waiting-for-info waiting for answer from issue creator

Comments

@mariel-sendblocks
Copy link

mariel-sendblocks commented Jul 27, 2023

According to the docs, the tracer diagnostic/startup logs arent printed in json format. The actual diagnostic/config are in json format, but they are printed as part of non-json log msg :
2020/07/09 15:57:07 Datadog Tracer v1.26.0 INFO: DATADOG TRACER CONFIGURATION {"date":"2020-07-09T15:57:07-05:00","os_name":"darwin","os_version":"10.15.4","version":"v1.26.0","lang":"Go","lang_version":"go1.14.2","env":"","service":"splittest2","agent_url":"http://127.0.0.1:8126/v0.4/traces","agent_error":"","debug":true,"analytics_enabled":false,"sample_rate":"NaN","sampling_rules":null,"sampling_rules_error":"","tags":{"runtime-id":"d269781c-b1bf-4d7b-9a55-a8174930554f"},"runtime_metrics_enabled":false,"health_metrics_enabled":false,"dd_version":"","architecture":"amd64","global_service":""}

Version of dd-trace-go

latest

Describe what happened:

general issue

Describe what you expected: The whole log should be printed in json format

Steps to reproduce the issue:

Additional environment details (Version of Go, Operating System, etc.):

@mariel-sendblocks mariel-sendblocks added the bug unintended behavior that has to be fixed label Jul 27, 2023
@knusbaum knusbaum added tracer waiting-for-info waiting for answer from issue creator proposal more in depth change that requires full team approval and removed bug unintended behavior that has to be fixed labels Aug 10, 2023
@knusbaum knusbaum changed the title [BUG] Tracer diagnostic and startup logs are not in json format ddtrace/tracer: diagnostic and startup logs should be in JSON format. Aug 10, 2023
@knusbaum
Copy link
Contributor

Hi @mariel-sendblocks.

This is an intentional behavior of the tracer. If you can point to the documentation that states they should be completely in JSON format, we can clarify there.

I've shifted this from a bug to a proposal.
I'd like to understand what the use case is for this being entirely JSON and we can discuss options.

@mariel-sendblocks
Copy link
Author

Hey @knusbaum ,
Since the datadog collects all the content of the logs, those logs arrive the datadog ui as ERRORS. The tracer configuration indeed printed as a json, but its part of a log message that itself isnt json-formatted.
I would expect to have the ability to configure the tracer's log message format.

@nsrip-dd
Copy link
Contributor

See also #2077. If we support slog, then the user can supply a JSON handler and we can provide the startup info to a slog.Logger so that it gets structured as a proper JSON record (without the leading timestamp)

@ahmed-mez
Copy link
Contributor

Hey @mariel-sendblocks

As mentioned in the docs, these prefixes are meant to simplify the search within your logs. They are also unified across the different Datadog tracers.

Tracer startup logs capture all obtainable information at startup and log it as DATADOG TRACER CONFIGURATION, DATADOG TRACER DIAGNOSTICS, DATADOG ERROR, or DATADOG CONFIGURATION to simplify searching within your logs.

While we don't expect to change the current default format of these logs in dd-trace-go, we're not against giving users the ability to reformat the logs and use any other formats they want (including JSON). We're happy to review and guide any contributions to allow doing this.

For better tracking and prioritization, you can also reach out to the support team and submit a feature request. Thanks.

@tspearconquest
Copy link

Hello, I'm interested in this and have opened a support case. We're facing the issue that Traefik Ingress Controller uses this library and while we have Traefik configured for JSON logging, this library is still logging to plaintext, which is breaking log parsing by Fluentd for our Traefik logs.

@rarguelloF
Copy link
Contributor

👋 @tspearconquest

As a workaround for this issue, you can use the tracer.WithLogger option (from gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer) to provide your existing JSON logger to the tracer:

package main

import (
	"go.uber.org/zap"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

type ddLogger struct {
	logger *zap.Logger
}

func (d *ddLogger) Log(msg string) {
	d.logger.Info(msg)
}

func main() {
	// initialize your JSON logger - in this example I'm using go.uber.org/zap
	logger, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	defer logger.Sync()

	tracer.Start(tracer.WithLogger(&ddLogger{logger: logger}))
	defer tracer.Stop()

	// ...
}

We are aware the existing ddtrace.Logger interface is limited as it doesn't expose some information like the log level or the key/value fields, but it should be enough to fix your existing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal more in depth change that requires full team approval tracer waiting-for-info waiting for answer from issue creator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants