https://authzed.com logo
Hi is it possible to add extra fields to
e

Elvia

03/22/2023, 2:14 PM
Hi, is it possible to add extra fields to the logs that are created in spicedb?
v

vroldanbet

03/22/2023, 2:21 PM
hi, I think the answer is not out of the box. I've done this myself by adding a middleware layer (middleware is part of SpiceDB exported Go API) and injecting your values into the context, like this:
ctx := log.Ctx(ctx).With().Str("my-key", "my-value").Logger().WithContext(ctx)
@jzelinskie maybe you know an alternative way?
e

Elvia

03/22/2023, 2:39 PM
How do you access the middleware? I'm new to Go, so I can't really wrap my head around it 😄
v

vroldanbet

03/22/2023, 2:41 PM
it looks like this when you are programatically creating a new server:
configOpts := []server.ConfigOption{
        server.WithMiddlewareModification(server.MiddlewareModification{
            DependencyMiddlewareName: server.DefaultInternalMiddlewareServerVersion,
            Operation:                server.OperationAppend,
            Middlewares: []server.ReferenceableMiddleware{
                {
                    Name:                "yourmiddleware",
                    UnaryMiddleware:     yourunarymiddleware
                    StreamingMiddleware: yourstreamingmiddleware,
                },
            },
        }),
    }

    return server.NewConfigWithOptions(configOpts...).Complete(ctx)