Skip to content

Commit

Permalink
fix: missing global in browser environments
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed May 18, 2020
1 parent 52f583d commit ebb45c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion karma.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ module.exports = {
// added to the webpack bundle for Karma tests.
{ parser: { node: webpackNodePolyfills } }
]
}
},
node: false
};
6 changes: 5 additions & 1 deletion packages/opentelemetry-api/src/api/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ type MyGlobals = Partial<{
[GLOBAL_TRACE_API_KEY]: Get<TracerProvider>;
}>;

export const _global = global as typeof global & MyGlobals;
export const _global = (typeof globalThis === 'object'
? globalThis
: typeof global === 'object'
? global
: window) as MyGlobals;

/**
* Make a function which accepts a version integer and returns the instance of an API if the version
Expand Down

0 comments on commit ebb45c8

Please sign in to comment.