Skip to content

Commit

Permalink
Include dids in bsky logs (bluesky-social#2015)
Browse files Browse the repository at this point in the history
* include dids in bsky logs

* tidy
devinivy authored Jan 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d03ddd0 commit 51aa369
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/bsky/package.json
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
"http-errors": "^2.0.0",
"http-terminator": "^3.2.0",
"ioredis": "^5.3.2",
"jose": "^5.0.1",
"kysely": "^0.22.0",
"multiformats": "^9.9.0",
"murmurhash": "^2.0.1",
32 changes: 32 additions & 0 deletions packages/bsky/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pino from 'pino'
import pinoHttp from 'pino-http'
import * as jose from 'jose'
import { subsystemLogger } from '@atproto/common'
import { parseBasicAuth } from './auth-verifier'

export const dbLogger: ReturnType<typeof subsystemLogger> =
subsystemLogger('bsky:db')
@@ -21,5 +24,34 @@ export const loggerMiddleware = pinoHttp({
message: err?.message,
}
},
req: (req) => {
const serialized = pino.stdSerializers.req(req)
const authHeader = serialized.headers.authorization || ''
let auth: string | undefined = undefined
if (authHeader.startsWith('Bearer ')) {
const token = authHeader.slice('Bearer '.length)
const { iss } = jose.decodeJwt(token)
if (iss) {
auth = 'Bearer ' + iss
} else {
auth = 'Bearer Invalid'
}
}
if (authHeader.startsWith('Basic ')) {
const parsed = parseBasicAuth(authHeader)
if (!parsed) {
auth = 'Basic Invalid'
} else {
auth = 'Basic ' + parsed.username
}
}
return {
...serialized,
headers: {
...serialized.headers,
authorization: auth,
},
}
},
},
})
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51aa369

Please sign in to comment.