Skip to content

Add access to the EMF data as map[string]interface{} #11

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

Closed
wants to merge 2 commits into from

Conversation

gaeste
Copy link

@gaeste gaeste commented Jul 3, 2023

Provide ability to retrieve the raw EMF data

In order to include the "_aws" as a named attribute in our logging system we would like to create it with your library (excellent and clean), but then apply it with our normal setup.

Example with our current solution and embedding some statistics in our logs as named value pairs:

	log.WithContext(ctx).
		With("duration_ms", time.Since(start).Milliseconds()).
		With("count", len(my_arr)).
		Debug("Items found")

To add EMF with this lib we would like to add a function for EMF that is plug and play with current logging interface, like:

	metrics := emf.New().
		Namespace("TLSDiscoveryNamespace").
		Dimension("dim", "example").
		MetricAs("counter", 1, emf.Count).
		Build()

	// The Build() exposes the map that is normally marshalled and makes it easy to integrate
	log.WithContext(ctx).WithMetrics(metrics).Info("items found")

With current implementation we would need to unmarshal the bytes from log:

	var buf bytes.Buffer
	metrics := emf.New(&buf).
		Namespace("TLSDiscoveryNamespace").
		Dimension("dim", "example").
		MetricAs("counter", 1, emf.Count).
		Log()

	// WithMetrics unmarshal the bytes to map in order to add the _aws metrics on proper level
	log.WithContext(ctx).WithMetrics(buf.Bytes()).Info("items found")

I see this mainly as a convenience method, but we would really love to see it, or something similar, included.

@gaeste gaeste closed this Jul 3, 2023
@gaeste gaeste deleted the add-access-to-emf-map branch July 3, 2023 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants