Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Always read thrift defs from ./ to better support bundling (#441)
Browse files Browse the repository at this point in the history
Always reading the jaeger thrift definition file from the root dir (src)
allows consumers to bundle jaeger-client, e.g. for uploading code to an
AWS lambda function.

To bundle jaeger-client with webpack for example, the thrift file needs
to be copied into the output directory of the bundle like this:

```js
{
  plugins: [
    new CopyPlugin([
      {
        from: require.resolve(
          'jaeger-client/dist/src/jaeger-idl/thrift/jaeger.thrift'
        ),
        to: 'jaeger-idl/thrift/jaeger.thrift'
      }
    ])
  ]
}
```

With this in place `fs.readFileSync` will be able to find the file.

Signed-off-by: Hendrik Liebau <mail@hendrik-liebau.de>
  • Loading branch information
unstubbable authored Aug 14, 2020
1 parent 0a11521 commit 67838e6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ tracer.registerExtractor(opentracing.FORMAT_HTTP_HEADERS, codec);
This can prove useful when compatibility with existing Zipkin tracing/instrumentation is desired.
### Webpack Compatibility
In order to bundle the library using webpack, e.g. for uploading code to an AWS Lambda function, it is required to copy the Jaeger thrift definition file into the output directory of the bundle:
```js
{
plugins: [
new CopyPlugin([
{
from: require.resolve('jaeger-client/dist/src/jaeger-idl/thrift/jaeger.thrift'),
to: 'jaeger-idl/thrift/jaeger.thrift',
},
]),
];
}
```
## License
[Apache 2.0 License](./LICENSE).
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Thrift } from 'thriftrw';

import NullLogger from '../logger.js';
import SenderUtils from './sender_utils.js';
import ThriftUtils from '../thrift.js';

const DEFAULT_PATH = '/api/traces';
const DEFAULT_PORT = 14268;
Expand Down Expand Up @@ -55,7 +56,7 @@ export default class HTTPSender {

this._logger = options.logger || new NullLogger();
this._jaegerThrift = new Thrift({
source: fs.readFileSync(path.join(__dirname, '../jaeger-idl/thrift/jaeger.thrift'), 'ascii'),
source: ThriftUtils.loadJaegerThriftDefinition(),
allowOptionalArguments: true,
});

Expand Down
3 changes: 2 additions & 1 deletion src/reporters/udp_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import path from 'path';
import { Thrift } from 'thriftrw';
import NullLogger from '../logger';
import SenderUtils from './sender_utils';
import ThriftUtils from '../thrift';
import Utils from '../util';

const HOST = 'localhost';
Expand Down Expand Up @@ -56,7 +57,7 @@ export default class UDPSender {
allowFilesystemAccess: true,
});
this._jaegerThrift = new Thrift({
source: fs.readFileSync(path.join(__dirname, '../jaeger-idl/thrift/jaeger.thrift'), 'ascii'),
source: ThriftUtils.loadJaegerThriftDefinition(),
allowOptionalArguments: true,
});
this._totalSpanBytes = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/thrift.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import Utils from './util.js';

export default class ThriftUtils {
static _thrift = new Thrift({
source: fs.readFileSync(path.join(__dirname, './jaeger-idl/thrift/jaeger.thrift'), 'ascii'),
source: ThriftUtils.loadJaegerThriftDefinition(),
allowOptionalArguments: true,
});
static emptyBuffer: Buffer = Utils.newBuffer(8);

static loadJaegerThriftDefinition(): string {
return fs.readFileSync(path.join(__dirname, './jaeger-idl/thrift/jaeger.thrift'), 'ascii');
}

static getThriftTags(initialTags: Array<Tag>): Array<any> {
let thriftTags = [];
for (let i = 0; i < initialTags.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('http sender', () => {

beforeEach(() => {
thrift = new Thrift({
source: fs.readFileSync(path.join(__dirname, '../src/jaeger-idl/thrift/jaeger.thrift'), 'ascii'),
source: ThriftUtils.loadJaegerThriftDefinition(),
allowOptionalArguments: true,
});

Expand Down

0 comments on commit 67838e6

Please sign in to comment.