Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add github actions deploy #1

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on:
push:
branches:
- main
tags:
- '**'
pull_request: {}

env:
COLUMNS: 150

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- uses: actions/setup-node@v4

- run: npm install
- run: ./gen_proto.sh

- uses: pre-commit/[email protected]
with:
extra_args: --all-files

- uses: cloudflare/wrangler-action@v3
with:
command: deploy --dry-run --var GITHUB_SHA:${{ github.sha }}

deploy:
if: "success() && github.ref == 'refs/heads/main'"
runs-on: ubuntu-latest
needs: [lint]
environment: cloudflare-workers-deploy

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4

- run: npm install
- run: ./gen_proto.sh

- uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.cloudflare_api_token }}
command: deploy --var GITHUB_SHA:${{ github.sha }}
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files

- repo: local
hooks:
- id: format
name: Format
entry: npm run format
types: [ts]
language: system
pass_filenames: false
- id: lint
name: Lint
entry: npm run lint
types: [ts]
language: system
pass_filenames: false
- id: typecheck
name: Typecheck
entry: npm run typecheck
types: [ts]
language: system
pass_filenames: false
File renamed without changes.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"format": "prettier --write -- .",
"lint": "prettier --check -- .",
"gen_proto": "./gen_proto.sh",
"typecheck": "npm run --workspaces typecheck",
"typecheck": "tsc --noEmit",
"dev": "wrangler dev",
"cf-typegen": "wrangler types"
},
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { convert, encodeTraces, decodeLogs } from './otel'

export interface Env {
GITHUB_SHA: string
}

export default {
async fetch(request, env, ctx): Promise<Response> {
// 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}.`)
} else if (pathname !== '/v1/logs' || request.method !== 'POST') {
return new Response('Only POST requests to `/v1/logs` are supported', { status: 404 })
}

const auth = request.headers.get('Authorization')
if (!auth) {
Expand Down Expand Up @@ -36,7 +46,7 @@ export default {
method: 'POST',
headers: {
'Content-Type': 'application/x-protobuf',
'Authorization': auth,
Authorization: auth,
'User-Agent': `logfire-logs-proxy ${request.headers.get('User-Agent')}`,
},
body: encodeTraces(traceRequest),
Expand Down
2 changes: 1 addition & 1 deletion src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function mapLogRecord(logRecord: ILogRecord): ISpan {
attributes.push({ key: 'log_body', value: logRecord.body })
}
}
let {traceId, spanId} = logRecord
let { traceId, spanId } = logRecord
if (!traceId || traceId.length === 0) {
traceId = generateRand(16)
}
Expand Down
3 changes: 3 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ name = "logfire-logs-proxy"
main = "src/index.ts"
compatibility_date = "2024-12-24"
compatibility_flags = ["nodejs_compat"]

[vars]
GITHUB_SHA = "unknown"
Loading