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

integrate metrics with logs #5

Open
komuw opened this issue Jan 30, 2023 · 1 comment
Open

integrate metrics with logs #5

komuw opened this issue Jan 30, 2023 · 1 comment

Comments

@komuw
Copy link
Owner

komuw commented Jan 30, 2023

  • we have already integrated logs with tracing. It would be nice to integrate metrics with logs, that way; you can navigate from metrics to the associated logs.
  • also probably integrate with tracing, so that you can be able to navigate from metrics to associated traces.

We could take the metric tags/labels/attributes and add them to logs and/or traces;

otero/service.go

Lines 84 to 88 in d9e1e77

// labels/tags
[]attribute.KeyValue{
attribute.String("handler_name", "serviceA_HttpHandler"),
attribute.Int64("req_size", r.ContentLength),
}...,

@komuw
Copy link
Owner Author

komuw commented Jan 30, 2023

diff --git a/service.go b/service.go
index 43ad22e..79481d8 100644
--- a/service.go
+++ b/service.go
@@ -7,6 +7,7 @@ import (
    "net/http"

    "github.com/komuw/otero/log"
+   "github.com/sirupsen/logrus"

    "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
    "go.opentelemetry.io/otel"
@@ -78,19 +79,25 @@ func serviceA_HttpHandler(w http.ResponseWriter, r *http.Request) {
        "service_a_called_counter",
        instrument.WithDescription("how many time the serviceA handler has been called."),
    )
+   attrs := []attribute.KeyValue{
+       attribute.String("handler_name", "serviceA_HttpHandler"),
+       attribute.Int64("req_size", r.ContentLength),
+   }
    counter.Add(
        ctx,
        1,
        // labels/tags
-       []attribute.KeyValue{
-           attribute.String("handler_name", "serviceA_HttpHandler"),
-           attribute.Int64("req_size", r.ContentLength),
-       }...,
+       attrs...,
    )

-   log := log.NewLogrus(ctx)
+   log := log.NewLogrus(ctx).WithFields(logrus.Fields{
+       "handler_name": attrs[0].Value,
+       "req_size":     attrs[1].Value,
+   })
    log.Info("serviceA_HttpHandler called")

+   span.SetAttributes(attrs...)
+
    // When serviceA is called, it calls serviceB over tcp network.

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

No branches or pull requests

1 participant