-
Notifications
You must be signed in to change notification settings - Fork 22
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
chore: add more otel params #716
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package telemetry | |
import ( | ||
"context" | ||
|
||
"github.com/RHEnVision/provisioning-backend/internal/identity" | ||
"github.com/RHEnVision/provisioning-backend/internal/logging" | ||
"github.com/rs/zerolog" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/codes" | ||
|
@@ -26,11 +28,37 @@ func (e *loggerExporter) ExportSpans(ctx context.Context, spans []trace.ReadOnly | |
parentId := span.Parent().SpanID() | ||
statusCode := span.Status().Code | ||
statusMsg := span.Status().Description | ||
|
||
t := e.logger.Trace(). | ||
Str("trace_id", traceId). | ||
Str("span_id", spanId). | ||
Dur("duration", duration) | ||
|
||
accountId := identity.AccountIdOrZero(ctx) | ||
if accountId != 0 { | ||
t = t.Int64("account_id", accountId) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the gist of the patch - I need to have in our zerolog exporter (which is used on stage/prod) request id which I can use to correlate all the records. It was not present at all, only trace_id which is unfortunately different because we cannot use it between api and worker pods (it gets closed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The job_id and job_type should be optional (set only when available) IMO, not to set them from all processes, having them blank may confuse us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, rebased. All fields are now compared and only added when needed. |
||
if requestId := logging.EdgeRequestId(ctx); requestId != "" { | ||
t = t.Str("request_id", requestId) | ||
} | ||
|
||
if orgId := identity.Identity(ctx).Identity.OrgID; orgId != "" { | ||
t = t.Str("org_id", orgId) | ||
} | ||
|
||
if accNum := identity.Identity(ctx).Identity.AccountNumber; accNum != "" { | ||
t = t.Str("account_number", accNum) | ||
} | ||
|
||
if jobId := logging.JobId(ctx); jobId != "" { | ||
t = t.Str("job_id", jobId) | ||
} | ||
|
||
if jobType := logging.JobType(ctx); jobType != "" { | ||
t = t.Str("job_type", jobType) | ||
} | ||
|
||
if parentId.IsValid() { | ||
t = t.Str("span_id_parent", parentId.String()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,8 @@ func contextLogger(origCtx context.Context, job *Job) (context.Context, *zerolog | |
ctx = logging.WithTraceId(ctx, job.TraceID) | ||
ctx = logging.WithEdgeRequestId(ctx, job.EdgeID) | ||
ctx = identity.WithAccountId(ctx, job.AccountID) | ||
ctx = logging.WithJobId(ctx, job.ID.String()) | ||
ctx = logging.WithJobType(ctx, job.Type.String()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition, I add job id and type which is sometimes useful for correlating records. For this I need to put these into context when job starts. |
||
|
||
logger := zerolog.Ctx(ctx) | ||
logger = ptr.To(logger.With(). | ||
|
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 had wrong name, it does not return
nil
but0
in fact.