Skip to content

Commit 3b36ffa

Browse files
Add support for structured logs (#323)
* wip on refactoring docs * wip * initial structured logs impl * structured log docs * create logger package * add news entry for structured logging * add logger package to dockerfile and cleanup * add gh workflow for catching broken links * further wip * fix * further wip on docs * review feedback * remove logger dep from mcp package * fix build errors * add back auth_url warning * fix sidebar title consistency --------- Co-authored-by: bkellam <[email protected]>
1 parent 82a786a commit 3b36ffa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+490
-222
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ COPY ./packages/db ./packages/db
4242
COPY ./packages/schemas ./packages/schemas
4343
COPY ./packages/crypto ./packages/crypto
4444
COPY ./packages/error ./packages/error
45+
COPY ./packages/logger ./packages/logger
4546

4647
RUN yarn workspace @sourcebot/db install
4748
RUN yarn workspace @sourcebot/schemas install
4849
RUN yarn workspace @sourcebot/crypto install
4950
RUN yarn workspace @sourcebot/error install
51+
RUN yarn workspace @sourcebot/logger install
5052
# ------------------------------------
5153

5254
# ------ Build Web ------
@@ -89,6 +91,7 @@ COPY --from=shared-libs-builder /app/packages/db ./packages/db
8991
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
9092
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
9193
COPY --from=shared-libs-builder /app/packages/error ./packages/error
94+
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
9295

9396
# Fixes arm64 timeouts
9497
RUN yarn workspace @sourcebot/web install
@@ -128,6 +131,7 @@ COPY --from=shared-libs-builder /app/packages/db ./packages/db
128131
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
129132
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
130133
COPY --from=shared-libs-builder /app/packages/error ./packages/error
134+
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
131135
RUN yarn workspace @sourcebot/backend install
132136
RUN yarn workspace @sourcebot/backend build
133137

@@ -209,6 +213,7 @@ COPY --from=shared-libs-builder /app/packages/db ./packages/db
209213
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
210214
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
211215
COPY --from=shared-libs-builder /app/packages/error ./packages/error
216+
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
212217

213218
# Configure dependencies
214219
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor uuidgen curl perl jq redis postgresql postgresql-contrib openssl util-linux unzip

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"docs/configuration/auth/roles-and-permissions"
7575
]
7676
},
77-
"docs/configuration/transactional-emails"
77+
"docs/configuration/transactional-emails",
78+
"docs/configuration/structured-logging"
7879
]
7980
},
8081
{

docs/docs/configuration/auth/overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Overview
33
---
44

5+
<Warning>If you're deploying Sourcebot behind a domain, you must set the [AUTH_URL](/docs/configuration/environment-variables) environment variable.</Warning>
6+
57
Sourcebot has built-in authentication that gates access to your organization. OAuth, email codes, and email / password are supported.
68

79
The first account that's registered on a Sourcebot deployment is made the owner. All other users who register must be [approved](/docs/configuration/auth/overview#approving-new-members) by the owner.
@@ -40,8 +42,6 @@ See [transactional emails](/docs/configuration/transactional-emails) for more de
4042

4143
## Enterprise Authentication Providers
4244

43-
<Warning>If you're deploying Sourcebot behind a domain, you must set the [AUTH_URL](/docs/configuration/environment-variables) environment variable to use these providers.</Warning>
44-
4545
The following authentication providers require an [enterprise license](/docs/license-key) to be enabled.
4646

4747
By default, a new user registering using these providers must have their join request accepted by the owner of the organization to join. To allow a user to join automatically when

docs/docs/configuration/auth/roles-and-permissions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Roles and Permissions
3+
sidebarTitle: Roles and permissions
34
---
45

56
<Note>Looking to sync permissions with your identify provider? We're working on it - [reach out](https://www.sourcebot.dev/contact) to us to learn more</Note>

docs/docs/configuration/environment-variables.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The following environment variables allow you to configure your Sourcebot deploy
2727
| `SMTP_CONNECTION_URL` | `-` | <p>The url to the SMTP service used for sending transactional emails. See [this doc](/docs/configuration/transactional-emails) for more info.</p> |
2828
| `SOURCEBOT_ENCRYPTION_KEY` | Automatically generated at startup if no value is provided. Generated using `openssl rand -base64 24` | <p>Used to encrypt connection secrets and generate API keys.</p> |
2929
| `SOURCEBOT_LOG_LEVEL` | `info` | <p>The Sourcebot logging level. Valid values are `debug`, `info`, `warn`, `error`, in order of severity.</p> |
30+
| `SOURCEBOT_STRUCTURED_LOGGING_ENABLED` | `false` | <p>Enables/disable structured JSON logging. See [this doc](/docs/configuration/structured-logging) for more info.</p> |
31+
| `SOURCEBOT_STRUCTURED_LOGGING_FILE` | - | <p>Optional file to log to if structured logging is enabled</p> |
3032
| `SOURCEBOT_TELEMETRY_DISABLED` | `false` | <p>Enables/disables telemetry collection in Sourcebot. See [this doc](/docs/overview.mdx#telemetry) for more info.</p> |
3133
| `TOTAL_MAX_MATCH_COUNT` | `100000` | <p>The maximum number of matches per query</p> |
3234
| `ZOEKT_MAX_WALL_TIME_MS` | `10000` | <p>The maximum real world duration (in milliseconds) per zoekt query</p> |
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Structured logging
3+
---
4+
5+
By default, Sourcebot will output logs to the console in a human readable format. If you'd like Sourcebot to output structured JSON logs, set the following env vars:
6+
7+
- `SOURCEBOT_STRUCTURED_LOGGING_ENABLED` (default: `false`): Controls whether logs are in a structured JSON format
8+
- `SOURCEBOT_STRUCTURED_LOGGING_FILE`: If structured logging is enabled and this env var is set, structured logs will be written to this file (ex. `/data/sourcebot.log`)
9+
10+
### Structured log schema
11+
```json
12+
{
13+
"$schema": "http://json-schema.org/draft-07/schema#",
14+
"type": "object",
15+
"title": "SourcebotLog",
16+
"properties": {
17+
"level": {
18+
"type": "string",
19+
"description": "The log level (error, warning, info, debug)"
20+
},
21+
"service": {
22+
"type": "string",
23+
"description": "The Sourcebot component that generated the log"
24+
},
25+
"message": {
26+
"type": "string",
27+
"description": "The log message"
28+
},
29+
"status": {
30+
"type": "string",
31+
"description": "The same value as the level field added for datadog support"
32+
},
33+
"timestamp": {
34+
"type": "string",
35+
"description": "The timestamp of the log in ISO 8061 format"
36+
}
37+
}
38+
}
39+
```

docs/docs/connections/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A JSON configuration file is used to specify connections. For example:
4343

4444
Configuration files must conform to the [JSON schema](#schema-reference).
4545

46-
When running Sourcebot, this file must be mounted in a volume that is accessible to the container, with it's path specified in the `CONFIG_PATH` environment variable. For example:
46+
When running Sourcebot, this file must be mounted in a volume that is accessible to the container, with its path specified in the `CONFIG_PATH` environment variable. For example:
4747

4848
```bash
4949
docker run \

docs/docs/deployment-guide.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Watch this 1:51 minute video to get a quick overview of how to deploy Sourcebot
5353
</Step>
5454

5555
<Step title="Launch your instance">
56+
<Warning>If you're deploying Sourcebot behind a domain, you must set the [AUTH_URL](/docs/configuration/environment-variables) environment variable.</Warning>
57+
58+
5659
In the same directory as `config.json`, run the following command to start your instance:
5760

5861
``` bash

docs/docs/features/agents/review-agent.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: AI Code Review Agent
3-
sidebarTitle: AI Code Review Agent
3+
sidebarTitle: AI code review agent
44
---
55

66
<Note>

packages/backend/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
},
2424
"dependencies": {
2525
"@gitbeaker/rest": "^40.5.1",
26-
"@logtail/node": "^0.5.2",
27-
"@logtail/winston": "^0.5.2",
2826
"@octokit/rest": "^21.0.2",
2927
"@sentry/cli": "^2.42.2",
3028
"@sentry/node": "^9.3.0",
3129
"@sentry/profiling-node": "^9.3.0",
3230
"@sourcebot/crypto": "workspace:*",
3331
"@sourcebot/db": "workspace:*",
3432
"@sourcebot/error": "workspace:*",
33+
"@sourcebot/logger": "workspace:*",
3534
"@sourcebot/schemas": "workspace:*",
3635
"@t3-oss/env-core": "^0.12.0",
3736
"@types/express": "^5.0.0",
@@ -51,7 +50,6 @@
5150
"prom-client": "^15.1.3",
5251
"simple-git": "^3.27.0",
5352
"strip-json-comments": "^5.0.1",
54-
"winston": "^3.15.0",
5553
"zod": "^3.24.3"
5654
}
5755
}

0 commit comments

Comments
 (0)