-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[accountingservice] adds otel logging support #1477
[accountingservice] adds otel logging support #1477
Conversation
…g log.WithContext()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Kimbohlovette, thanks for taking care of this.
I've tested the PR but I can't see any logs being exported from accountingservice
via OTLP.
From the OTel Go repo, I can see that this is still in development.
@pellared do we already have a sample/test for Go OTLP logs?
Alright @julianocosta89. I focused on reproducing the same behavior using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does NOT use any bridge using OTel Go Logs Bridge API (experimental) nor OTel Go Logs SDK (under-development).
@pellared is there some recommendation on what I should do to implement what we want? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is using https://github.com/uptrace/opentelemetry-go-extra, not OpenTelemetry Logging. I'm not sure what the state of the upstream logging bridges are, but I don't think this actually 'adds logging support' at all, rather it's using the logrus utility from the linked repo to attach logs as span events.
|
Okay @pellared many thanks, I will try to implement it that way. If I get any difficulties I will ping you guys immediately |
Can you please convert this PR to a draft until it is ready to review? |
Okay |
Hello @pellared I just replaced |
As mentioned, it is under-development. You need to wait. |
Okay thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a quick review for you.
src/accountingservice/main.go
Outdated
} | ||
log.Out = os.Stdout | ||
func initLogger() *slog.Logger { | ||
logger := slog.New(slog.NewJSONHandler(os.Stderr, nil)).With("service", "accounting") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the place where you would use to otelslog
bridge instead of slog.NewJSONHandle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
src/accountingservice/main.go
Outdated
tp, err := initTracerProvider() | ||
if err != nil { | ||
log.Fatal(err) | ||
logger.LogAttrs(ctx, slog.LevelError, "failed to initialize trace provider", slog.String("error", err.Error())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.LogAttrs(ctx, slog.LevelError, "failed to initialize trace provider", slog.String("error", err.Error())) | |
logger.LogAttrs(ctx, slog.LevelError, "Failed to initialize trace provider", slog.String("error", err.Error())) |
src/accountingservice/main.go
Outdated
if err := tp.Shutdown(context.Background()); err != nil { | ||
log.Printf("Error shutting down tracer provider: %v", err) | ||
if err := tp.Shutdown(ctx); err != nil { | ||
logger.LogAttrs(ctx, slog.LevelError, "failed to shotdown properly", slog.String("error", err.Error())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.LogAttrs(ctx, slog.LevelError, "failed to shotdown properly", slog.String("error", err.Error())) | |
logger.LogAttrs(ctx, slog.LevelError, "Failed to shutdown properly", slog.String("error", err.Error())) |
src/accountingservice/main.go
Outdated
}() | ||
|
||
<-ctx.Done() | ||
|
||
log.Println("Accounting service exited") | ||
logger.Log(ctx, slog.LevelInfo, "message", "Accounting service exited") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.Log(ctx, slog.LevelInfo, "message", "Accounting service exited") | |
logger.LogAttrs(ctx, slog.LevelInfo, "Accounting service exited") |
src/accountingservice/main.go
Outdated
} | ||
log.Println("Shutdown trace provider") | ||
logger.LogAttrs(ctx, slog.LevelInfo, "", slog.String("message", "Shotdown trace provider")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.LogAttrs(ctx, slog.LevelInfo, "", slog.String("message", "Shotdown trace provider")) | |
logger.LogAttrs(ctx, slog.LevelInfo, "Shutdown trace provider") |
src/accountingservice/main.go
Outdated
log.Out = os.Stdout | ||
func initLogger() *slog.Logger { | ||
logger := slog.New(slog.NewJSONHandler(os.Stderr, nil)).With("service", "accounting") | ||
slog.SetDefault(logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you setting the default logger. You never use it afterwards.
Consider removing this line or not returning the logger in this function and using slog.LogAttrs
instead of logger.LogAttrs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I will do the changes as requested
Thank you for the reviews 😊
Okay 😊 |
I have mentained the initialization |
"messageTimestamp": message.Timestamp, | ||
"messageTopic": message.Topic, | ||
}).Info("Message claimed") | ||
g.log.LogAttrs(session.Context(), slog.LevelInfo, "Message claimed", slog.String("orderId", orderResult.OrderId), slog.String("messageTimestamp", message.Timestamp.String()), slog.String("messageTopic", message.Topic)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that session.Context()
would NOT contain the trace context information as NewOTelInterceptor
does not pass the context created in oi.tracer.Start
. Therefore, the logs would not contain the TraceID
and SpanID
fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so should I just use a new context like context.TODO()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should try to refine the sarama instrumentation so that you can propagate trace context to the logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
I spoke with @Kimbohlovette today and mentioned that this is not supported yet as OTel logs in Go are still in development. Closing this PR for now. |
@julianocosta89, @Kimbohlovette can still find out how to address #1477 (comment). Even though that OTel Go Logs are in development it still something that can be worked on. I cannot find anything more useful to help in OTel Go Logs. We will probably have a usable experimental release of OTel Go Logs this or next month. It is already possible to use Logs Bridge API and slog Bridge which is everything needed for addressing #1477 (comment). |
@pellared if we can make it work, than that would be great! Once we get one working, he can apply the same solution for the other 2 Go services. |
I already do my best to do so. |
Appreciate it! @Kimbohlovette would you be able to address #1477 (comment)? |
@julianocosta89 yes I will continue to work with @pellared and definitely get it done |
Feel free to re-open the issue whenever you have it in a working state |
Alright @julianocosta89 |
The PR implements logging in the accounting service with
slog
in order to theslog.LogAttrs()
which always receives the current context and attributes.Use the
otelslog
- currently in development to collect logs and send to open telemetry.