Skip to content

Commit 8060b00

Browse files
authoredDec 28, 2024··
add github actions deploy (#1)
1 parent b3aa001 commit 8060b00

File tree

7 files changed

+98
-4
lines changed

7 files changed

+98
-4
lines changed
 

‎.github/workflows/ci.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '**'
9+
pull_request: {}
10+
11+
env:
12+
COLUMNS: 150
13+
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: 'true'
21+
22+
- uses: actions/setup-node@v4
23+
24+
- run: npm install
25+
- run: ./gen_proto.sh
26+
27+
- uses: pre-commit/action@v3.0.1
28+
with:
29+
extra_args: --all-files
30+
31+
- uses: cloudflare/wrangler-action@v3
32+
with:
33+
command: deploy --dry-run --var GITHUB_SHA:${{ github.sha }}
34+
35+
deploy:
36+
if: "success() && github.ref == 'refs/heads/main'"
37+
runs-on: ubuntu-latest
38+
needs: [lint]
39+
environment: cloudflare-workers-deploy
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- uses: actions/setup-node@v4
45+
46+
- run: npm install
47+
- run: ./gen_proto.sh
48+
49+
- uses: cloudflare/wrangler-action@v3
50+
with:
51+
apiToken: ${{ secrets.cloudflare_api_token }}
52+
command: deploy --var GITHUB_SHA:${{ github.sha }}

‎.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-toml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- id: check-added-large-files
10+
11+
- repo: local
12+
hooks:
13+
- id: format
14+
name: Format
15+
entry: npm run format
16+
types: [ts]
17+
language: system
18+
pass_filenames: false
19+
- id: lint
20+
name: Lint
21+
entry: npm run lint
22+
types: [ts]
23+
language: system
24+
pass_filenames: false
25+
- id: typecheck
26+
name: Typecheck
27+
entry: npm run typecheck
28+
types: [ts]
29+
language: system
30+
pass_filenames: false

‎gen_logs.py ‎example_logs.py

File renamed without changes.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"scripts": {
66
"format": "prettier --write -- .",
77
"lint": "prettier --check -- .",
8-
"gen_proto": "./gen_proto.sh",
9-
"typecheck": "npm run --workspaces typecheck",
8+
"typecheck": "tsc --noEmit",
109
"dev": "wrangler dev",
1110
"cf-typegen": "wrangler types"
1211
},

‎src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { convert, encodeTraces, decodeLogs } from './otel'
22

3+
export interface Env {
4+
GITHUB_SHA: string
5+
}
6+
37
export default {
48
async fetch(request, env, ctx): Promise<Response> {
59
// console.log(Object.fromEntries(request.headers))
10+
const { pathname } = new URL(request.url)
11+
if (request.method === 'GET' && pathname === '/') {
12+
return new Response(`See https://github.com/pydantic/logfire-logs-proxy for details (commit ${env.GITHUB_SHA}.`)
13+
} else if (pathname !== '/v1/logs' || request.method !== 'POST') {
14+
return new Response('Only POST requests to `/v1/logs` are supported', { status: 404 })
15+
}
616

717
const auth = request.headers.get('Authorization')
818
if (!auth) {
@@ -36,7 +46,7 @@ export default {
3646
method: 'POST',
3747
headers: {
3848
'Content-Type': 'application/x-protobuf',
39-
'Authorization': auth,
49+
Authorization: auth,
4050
'User-Agent': `logfire-logs-proxy ${request.headers.get('User-Agent')}`,
4151
},
4252
body: encodeTraces(traceRequest),

‎src/otel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function mapLogRecord(logRecord: ILogRecord): ISpan {
8585
attributes.push({ key: 'log_body', value: logRecord.body })
8686
}
8787
}
88-
let {traceId, spanId} = logRecord
88+
let { traceId, spanId } = logRecord
8989
if (!traceId || traceId.length === 0) {
9090
traceId = generateRand(16)
9191
}

‎wrangler.toml

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ name = "logfire-logs-proxy"
22
main = "src/index.ts"
33
compatibility_date = "2024-12-24"
44
compatibility_flags = ["nodejs_compat"]
5+
6+
[vars]
7+
GITHUB_SHA = "unknown"

0 commit comments

Comments
 (0)