Skip to content

Commit

Permalink
fix protobuf google-api
Browse files Browse the repository at this point in the history
  • Loading branch information
wconti27 committed Sep 24, 2024
1 parent 6028c36 commit af12edb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/datadog-instrumentations/src/protobufjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,25 @@ function wrapReflection (protobuf) {
})
}

function isPromise (obj) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
}

addHook({
name: 'protobufjs',
versions: ['>=6.0.0']
}, protobuf => {
shimmer.wrap(protobuf.Root.prototype, 'load', original => {
return function wrappedLoad (...args) {
const result = original.apply(this, args)
result.then(root => {
wrapProtobufClasses(root)
})
if (isPromise(result)) {
result.then(root => {
wrapProtobufClasses(root)
})
} else {
// If result is not a promise, directly wrap the protobuf classes
wrapProtobufClasses(result)
}
return result
}
})
Expand Down

0 comments on commit af12edb

Please sign in to comment.