Skip to content

Commit

Permalink
experimental tracing of calls into dataplane from appview
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 3, 2024
1 parent 7a9c661 commit 6c2cecb
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions services/bsky/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
'use strict' /* eslint-disable */

require('dd-trace') // Only works with commonjs
.init({ logInjection: true })
.tracer.use('express', {
const dd = require('dd-trace')

// modify tracer in order to track calls to dataplane as a service with proper resource names
const DATAPLANE_PREFIX = '/bsky.Service/'
const origStartSpan = dd.tracer.startSpan
dd.tracer.startSpan = function (name, options) {
if (
name !== 'http.request' ||
options?.tags?.component !== 'http2' ||
!options?.tags?.['http.uri']
) {
return origStartSpan.call(this, name, options)
}
const uri = new URL(options.tags['http.uri'])
if (!uri.pathname.startsWith(DATAPLANE_PREFIX)) {
return origStartSpan.call(this, name, options)
}
options.tags['service.name'] = 'dataplane-bsky'
options.tags['resource.name'] = uri.pathname.slice(DATAPLANE_PREFIX.length)
return origStartSpan.call(this, name, options)
}

dd.tracer
.use('http2', {
client: true, // calls into dataplane
server: false,
})
.use('express', {
hooks: {
request: (span, req) => {
maintainXrpcResource(span, req)
Expand Down

0 comments on commit 6c2cecb

Please sign in to comment.