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

Always read thrift defs from ./ to better support bundling#441

Merged
yurishkuro merged 1 commit intojaegertracing:masterfrom
unstubbable:bundling
Aug 14, 2020
Merged

Always read thrift defs from ./ to better support bundling#441
yurishkuro merged 1 commit intojaegertracing:masterfrom
unstubbable:bundling

Conversation

@unstubbable
Copy link
Copy Markdown
Contributor

Always reading the jaeger thrift definition file from the root dir (i.e. 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:

{
  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 [email protected]

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 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 14, 2020

Codecov Report

Merging #441 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #441   +/-   ##
=======================================
  Coverage   98.71%   98.72%           
=======================================
  Files          50       50           
  Lines        2031     2035    +4     
  Branches      383      383           
=======================================
+ Hits         2005     2009    +4     
  Misses         26       26           
Impacted Files Coverage Δ
src/reporters/http_sender.js 100.00% <100.00%> (ø)
src/reporters/udp_sender.js 98.75% <100.00%> (+0.01%) ⬆️
src/thrift.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a11521...ecc58a7. Read the comment docs.

Copy link
Copy Markdown
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring LGTM, but I am not clear if it changes anything. How does it "Allow jaeger-client to be bundled"? Please elaborate.

I recall we had another PR (#424) to actually embed the thrift definitions into a JS file, but the author didn't have cycles to finish it.

@unstubbable
Copy link
Copy Markdown
Contributor Author

unstubbable commented Aug 14, 2020

With my change it is guaranteed that the thrift file is always loaded with a path that is relative to __dirname and starts with ./ (vs. ../ as before in two occurences). When a node application that requires jaeger-client is bundled into a single file, say dist/my-bundle.js, the thrift file can be resolved relative to the __dirname of the bundle, i.e. dist in my example. Therefore we can just copy the thrift file into the dist directory at dist/jaeger-idl/thrift/jaeger.thrift from where it can be read using fs.

Copy link
Copy Markdown
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks

@yurishkuro yurishkuro changed the title Allow jaeger-client to be bundled Always read thrift defs from ./ to better support bundling Aug 14, 2020
@yurishkuro yurishkuro merged commit 67838e6 into jaegertracing:master Aug 14, 2020
@unstubbable unstubbable deleted the bundling branch August 14, 2020 16:55
@yurishkuro
Copy link
Copy Markdown
Member

slaveofcode pushed a commit to slaveofcode/jaeger-client-node that referenced this pull request Oct 27, 2020
…racing#441)

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 <[email protected]>
Signed-off-by: Kresna <[email protected]>
yurishkuro pushed a commit that referenced this pull request Oct 30, 2021
Add a helper function in src/thrift.js that returns an absolute path to
agent.thrift, without using "../". This is done to simplify bundling with
webpack or esbuild: assume an app is bundled to /app/index.js, if we resolve
a path to "../thrift-idl/etc", the file will be loaded from /thrift-idl/etc,
which is at the root of the filesystem.

Adjust README to support udp-sender.

This commit is a continuation of #441.

Signed-off-by: Thorsten Nadel <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants