{"record":{"id":"1866b43b1af5dff7","repo":"SigNoz/signoz","slug":"failed-to-get-email-from-context","errorCode":null,"errorMessage":"failed to get email from context","messagePattern":"failed to get email from context","errorType":"http","errorClass":"model.ApiError","httpStatus":401,"severity":"error","filePath":"pkg/query-service/app/logparsingpipeline/db.go","lineNumber":53,"sourceCode":"func (r *Repo) insertPipeline(\n\tctx context.Context, orgID valuer.UUID, postable *pipelinetypes.PostablePipeline,\n) (*pipelinetypes.GettablePipeline, error) {\n\tif err := postable.IsValid(); err != nil {\n\t\treturn nil, errors.WithAdditionalf(err, \"pipeline is not valid\")\n\t}\n\n\trawConfig, err := json.Marshal(postable.Config)\n\tif err != nil {\n\t\treturn nil, errors.WrapInternalf(err, errors.CodeInternal, \"failed to unmarshal postable pipeline config\")\n\t}\n\tfilter, err := json.Marshal(postable.Filter)\n\tif err != nil {\n\t\treturn nil, errors.WrapInternalf(err, errors.CodeInternal, \"failed to marshal postable pipeline filter\")\n\t}\n\n\tclaims, errv2 := authtypes.ClaimsFromContext(ctx)\n\tif errv2 != nil {\n\t\treturn nil, model.UnauthorizedError(fmt.Errorf(\"failed to get email from context\"))\n\t}\n\n\tinsertRow := &pipelinetypes.GettablePipeline{\n\t\tStoreablePipeline: pipelinetypes.StoreablePipeline{\n\t\t\tOrgID: orgID.String(),\n\t\t\tIdentifiable: types.Identifiable{\n\t\t\t\tID: valuer.GenerateUUID(),\n\t\t\t},\n\t\t\tOrderID:      postable.OrderID,\n\t\t\tEnabled:      postable.Enabled,\n\t\t\tName:         postable.Name,\n\t\t\tAlias:        postable.Alias,\n\t\t\tDescription:  postable.Description,\n\t\t\tFilterString: string(filter),\n\t\t\tConfigJSON:   string(rawConfig),\n\t\t\tTimeAuditable: types.TimeAuditable{\n\t\t\t\tCreatedAt: time.Now(),\n\t\t\t},","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/logparsingpipeline/db.go#L35-L71","documentation":"insertPipeline in the log-parsing-pipeline DB layer extracts auth claims from the request context via authtypes.ClaimsFromContext; when that fails it maps the problem to an UnauthorizedError with this message. Despite the wording ('get email'), the real cause is missing/invalid authentication claims in ctx — the context was not authenticated (or the claims middleware did not run) before ApplyPipelines -> insertPipeline.","triggerScenarios":"Calling ApplyPipelines (which calls insertPipeline) with a context that carries no auth claims: unauthenticated gRPC/HTTP context, claims not propagated through a background job or test harness, or an expired/invalid JWT that the claims middleware refused to attach.","commonSituations":"Integration tests calling ApplyPipelines with context.Background(); internal services invoking the pipeline API without forwarding authorization headers/claims; middleware ordering that skips auth on a new route; expired API token.","solutions":["Ensure the call is made with an authenticated context — attach a valid JWT/API key so the auth middleware injects claims before ApplyPipelines runs.","In tests, inject claims explicitly (e.g. authtypes.InjectContext(ctx, claims) or your project's helper) instead of context.Background().","Verify middleware/route ordering so the pipeline endpoints are behind the auth layer.","If forwarding between services, propagate the Authorization metadata so ClaimsFromContext succeeds."],"exampleFix":"// before\npipeline, err := qs.ApplyPipelines(context.Background(), req) // no claims -> unauthorized\n\n// after\nctx := authtypes.InjectClaimsIntoContext(ctx, authtypes.Claims{Email: \"user@example.com\", UserID: ...})\npipeline, err := qs.ApplyPipelines(ctx, req)","handlingStrategy":"try-catch","validationCode":"if _, err := authtypes.ClaimsFromContext(ctx); err != nil {\n\treturn model.UnauthorizedError(fmt.Errorf(\"request is not authenticated\"))\n}","typeGuard":"func hasClaims(ctx context.Context) bool {\n\t_, err := authtypes.ClaimsFromContext(ctx)\n\treturn err == nil\n}","tryCatchPattern":"pipeline, err := qs.ApplyPipelines(ctx, req)\nif err != nil {\n\tif errors.Is(err, errors.ErrUnauthenticated) || strings.Contains(err.Error(), \"failed to get email from context\") {\n\t\t// re-authenticate / refresh token and retry once, or return 401\n\t}\n\treturn err\n}","preventionTips":["Never call ApplyPipelines with context.Background(); inject claims in services and tests.","Keep pipeline endpoints behind the auth middleware; add integration tests that exercise the authenticated path.","Propagate Authorization headers/metadata across service hops."],"tags":["authentication","context","unauthorized","log-pipelines","middleware"],"backgroundTag":"missing-auth-context","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}