Skip to content

Commit

Permalink
refactor: add log field filtering to remove unnecessary metadata (#197)
Browse files Browse the repository at this point in the history
### Description

This PR adds the `logDataTransformer` callback to the Loki Logging class
to filter specific fields in a log.

### Motivation

The `edge-gateway` worker currently produces logs with many unnecessary
fields that can be removed to reduce log data size and lower costs. More
details can be found in [issue
#175](storacha/project-tracking#175).

### Changes (edge-gateway)

- Upgraded `@web3-storage/worker-utils/loki` package to the latest
version
- Upgraded `toucan-js` to version 3.x for compatibility with
`@web3-storage/worker-utils/loki`
- Upgraded `@sentry/cli` to ensure compatibility with `toucan-js`
- Added `logDataTransformer` callback in the Loki Logging constructor
for custom log field filtering
  • Loading branch information
BravoNatalie authored Nov 14, 2024
1 parent d723fe6 commit 10e9d17
Show file tree
Hide file tree
Showing 3 changed files with 5,434 additions and 6,160 deletions.
8 changes: 4 additions & 4 deletions packages/edge-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"mock:cf-ipfs.com": "smoke -p 9083 test/mocks/cf-ipfs.com"
},
"dependencies": {
"@web3-storage/worker-utils": "^0.3.0-dev",
"@web3-storage/worker-utils": "^0.6.0-dev",
"ipfs-core-utils": "^0.15.0",
"ipfs-gateway-race": "link:../ipfs-gateway-race",
"itty-router": "^2.4.5",
Expand All @@ -28,12 +28,12 @@
"p-retry": "^5.0.0",
"p-settle": "^5.0.0",
"p-some": "^5.0.0",
"toucan-js": "^2.5.0",
"toucan-js": "^3.4.0",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^3.7.1",
"@sentry/cli": "^1.71.0",
"@sentry/cli": "^2.7.0",
"@types/git-rev-sync": "^2.0.0",
"@web-std/fetch": "^4.0.0",
"ava": "^3.15.0",
Expand Down Expand Up @@ -65,4 +65,4 @@
},
"author": "Vasco Santos <[email protected]>",
"license": "Apache-2.0 OR MIT"
}
}
31 changes: 20 additions & 11 deletions packages/edge-gateway/src/env.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* global BRANCH, VERSION, COMMITHASH, SENTRY_RELEASE */
import Toucan from 'toucan-js'
import { Toucan, RewriteFrames } from 'toucan-js'

import { Logging } from '@web3-storage/worker-utils/loki'
import { createGatewayRacer } from 'ipfs-gateway-race'

import pkg from '../package.json'
import {
DEFAULT_RACE_L1_GATEWAYS,
DEFAULT_RACE_L2_GATEWAYS,
Expand Down Expand Up @@ -68,7 +67,19 @@ export function envAll (request, env, ctx) {
branch: env.BRANCH,
worker: 'edge-gateway',
env: env.ENV,
sentry: env.sentry
sentry: env.sentry,
logDataTransformer: (log) => {
const { metadata } = log
const { request, ...restMetadata } = metadata

// Destructure to omit the `cf` field from `request`
const { cf, ...filteredRequest } = request

return {
...log,
metadata: { ...restMetadata, request: filteredRequest }
}
}
})
env.log.time('request')
}
Expand Down Expand Up @@ -111,15 +122,13 @@ function getSentry (request, env, ctx) {
request,
dsn: env.SENTRY_DSN,
context: ctx,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
requestDataOptions: {
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/
},
integrations: [new RewriteFrames({ root: '/' })],
debug: false,
environment: env.ENV || 'dev',
rewriteFrames: {
// sourcemaps only work if stack filepath are absolute like `/worker.js`
root: '/'
},
release: env.SENTRY_RELEASE,
pkg
release: env.SENTRY_RELEASE
})
}
Loading

0 comments on commit 10e9d17

Please sign in to comment.