Skip to content

Add initial logger implementation #1010

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

Merged
merged 27 commits into from
May 13, 2025
Merged

Add initial logger implementation #1010

merged 27 commits into from
May 13, 2025

Conversation

giortzisg
Copy link
Contributor

@giortzisg giortzisg commented May 8, 2025

Closes #1000.

Example usage of logger

package main

import (
	"context"
	"github.com/getsentry/sentry-go"
	"github.com/getsentry/sentry-go/attribute"
	"time"
)

func main() {
	err := sentry.Init(sentry.ClientOptions{
		Dsn:        "",
		EnableLogs: true,
	})
	if err != nil {
		panic(err)
	}
	defer sentry.Flush(2 * time.Second)

	ctx := context.Background()
	logger := sentry.NewLogger(ctx)

	// you can use the logger like [fmt.Print]
	logger.Info(ctx, "Expecting ", 2, " params")
	// or like [fmt.Printf]
	logger.Infof(ctx, "format: %v", "value")

	// and you can also set attributes on the log like this
	logger.SetAttributes(
		attribute.Int("key.int", 42),
		attribute.Bool("key.boolean", true),
		attribute.Float64("key.float", 42.4),
		attribute.String("key.string", "string"),
	)
	logger.Warnf(ctx, "I have params %v and attributes", "example param")
}

@giortzisg giortzisg requested a review from cleptric May 8, 2025 11:32
@giortzisg giortzisg self-assigned this May 8, 2025
Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 90.67797% with 22 lines in your changes missing coverage. Please review.

Project coverage is 85.42%. Comparing base (64de096) to head (74a43a0).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
log.go 91.66% 10 Missing and 1 partial ⚠️
batch_logger.go 84.48% 8 Missing and 1 partial ⚠️
transport.go 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1010      +/-   ##
==========================================
+ Coverage   85.12%   85.42%   +0.29%     
==========================================
  Files          53       55       +2     
  Lines        5276     5487     +211     
==========================================
+ Hits         4491     4687     +196     
- Misses        640      655      +15     
  Partials      145      145              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw this was in progress so did a preliminary review! Do you mind also adding some examples in the PR description of how log should be configured and used with this PR?

@giortzisg
Copy link
Contributor Author

giortzisg commented May 10, 2025

Thanks for the review Abhi. Will also add examples, nice catch.

@cleptric
Copy link
Member

For Debug: true:

Sending info event [a710bb92af79490b9135782c8924d613] to o1.ingest.us.sentry.io project:

instead we should emit something like

Sending X log events [a710bb92af79490b9135782c8924d613] to o1.ingest.us.sentry.io project:

@cleptric cleptric added the Feature Issue type label May 12, 2025
@giortzisg giortzisg requested a review from cleptric May 13, 2025 09:18
Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giortzisg giortzisg merged commit c340089 into master May 13, 2025
17 checks passed
@giortzisg giortzisg deleted the feat/logger branch May 13, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry Structured Logging for Go
4 participants