Skip to content

Commit

Permalink
update readme, update example to use worker endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Dec 29, 2024
1 parent c73c494 commit 3732fc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
Proxy for sending OTel logs to [Logfire](https://pydantic.dev/logfire).

Run as a CloudFlare Worker.

## Usage

Set your OTel logs endpoint to `https://logfire-logs-proxy.pydantic.workers.dev/v1/logs`.

Add the `Authorization` header are your [normally would with Logfire](https://logfire.pydantic.dev/docs/how-to-guides/alternative-clients/).

With that OTel logs should appear in logfire as traces.
7 changes: 5 additions & 2 deletions example_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
)
set_logger_provider(logger_provider)

endpoint = 'https://logfire-logs-proxy.pydantic.workers.dev/v1/logs'
# to run against a worker running locally
# endpoint = 'http://localhost:8787/v1/logs'
LOGFIRE_TOKEN = os.environ['LOGFIRE_TOKEN']
compression = Compression.Gzip
exporter = OTLPLogExporter(
endpoint='http://localhost:8787/v1/logs',
endpoint=endpoint,
headers={'Authorization': f'Bearer {LOGFIRE_TOKEN}'},
compression=compression
)
Expand All @@ -51,7 +54,7 @@

logger1.debug('debug %d', 41)
logger1.info('info %d, compression=%s', 42, compression)
logger1.warning('warning %d', 43)
logger1.warning('warning endpoint=%s', endpoint)
logger1.error('error %d', 44)


Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
// console.log(Object.fromEntries(request.headers))
const { pathname } = new URL(request.url)
if (request.method === 'GET' && pathname === '/') {
return new Response(`See https://github.com/pydantic/logfire-logs-proxy for details (commit ${env.GITHUB_SHA}.`)
return new Response(`See https://github.com/pydantic/logfire-logs-proxy for details (commit ${env.GITHUB_SHA}).`)
} else if (pathname !== '/v1/logs' || request.method !== 'POST') {
return new Response('Only POST requests to `/v1/logs` are supported', { status: 404 })
}
Expand Down

0 comments on commit 3732fc1

Please sign in to comment.