MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestLogHandler_WithFields

Function TestLogHandler_WithFields

lambdacontext/logger_test.go:255–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func TestLogHandler_WithFields(t *testing.T) {
256 var buf bytes.Buffer
257
258 opts := &slog.HandlerOptions{
259 Level: slog.LevelInfo,
260 ReplaceAttr: ReplaceAttr,
261 }
262 baseHandler := slog.NewJSONHandler(&buf, opts)
263
264 // Create options with fields
265 options := &logOptions{}
266 WithFunctionARN()(options)
267 WithTenantID()(options)
268
269 handler := &lambdaHandler{
270 handler: baseHandler,
271 fields: options.fields,
272 }
273
274 lc := &LambdaContext{
275 AwsRequestID: "test-request-123",
276 InvokedFunctionArn: "arn:aws:lambda:us-east-1:123456789:function:test",
277 TenantID: "tenant-abc",
278 }
279 ctx := NewContext(context.Background(), lc)
280
281 logger := slog.New(handler)
282 logger.InfoContext(ctx, "test message")
283
284 var logOutput map[string]interface{}
285 err := json.Unmarshal(buf.Bytes(), &logOutput)
286 require.NoError(t, err)
287
288 assert.Equal(t, "test-request-123", logOutput["requestId"])
289 assert.Equal(t, "arn:aws:lambda:us-east-1:123456789:function:test", logOutput["functionArn"])
290 assert.Equal(t, "tenant-abc", logOutput["tenantId"])
291}
292
293func TestLogHandler_WithFieldFunctionARNOnly(t *testing.T) {
294 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 3

WithFunctionARNFunction · 0.85
WithTenantIDFunction · 0.85
NewContextFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…