Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running cloud trace with webpack #774

Closed
smousa opened this issue Jun 13, 2018 · 9 comments
Closed

Running cloud trace with webpack #774

smousa opened this issue Jun 13, 2018 · 9 comments
Assignees
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. web

Comments

@smousa
Copy link

smousa commented Jun 13, 2018

When I try to start my nodejs service with trace, I see the following error:
ERROR:@google-cloud/trace-agent: TraceAgent#start: Tracing might not work as the following modules were loaded before the trace agent was initialized: [...]
and it lists every package dependency in my package.json.

I placed the declaration at the top of index.js:
require('@google-cloud/trace-agent').start({projectId: 'projectId'})

Which is where my webpack config js points to:

 module.exports = merge(baseWebpackConfig, {
    mode: "development",
    entry: ['webpack/hot/poll?500', './server/index'],
    ....
})

Do you know if I am doing something wrong?

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Jun 13, 2018
@kjin kjin added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Jun 13, 2018
@kjin
Copy link
Contributor

kjin commented Jun 13, 2018

We currently do not support webpack, since we assume that required modules reside in node_modules. I will look into whether we can support this -- but I'm not sure if it's possible.

@ofrobots
Copy link
Contributor

@smousa can you include some details on your motivation to use webpack on a server side project? As @kjin said, this is a use-case we have not considered up till now. We would like to understand why/how this is being used to figure what solutions might be possible.

@smousa
Copy link
Author

smousa commented Jun 14, 2018

Thanks for the reply. What I have been using webpack was primarily for hot module reloading. But I think I found a workaround for my immediate issue, which is to initialize tracing in a separate file, like trace.js, require the index and have webpack load trace.js first:

trace.js:

require('@google-cloud/trace-agent').start({samplingRate:0})                                                                                                                                                       
require('./index')

webpack.*.conf.js

module.exports = merge(baseWebpackConfig, {                                     
    mode: "development",                                                        
    entry: ['webpack/hot/poll?500', './server/trace'],                          
    watch: true,                                                                
    externals: [nodeExternals({whitelist:['webpack/hot/poll?500']})],
    ....

@soldair
Copy link
Contributor

soldair commented Feb 12, 2019

We've done some tests and found that we cannot not support webpack or bundlers at all at this point.
They "require" files in a way that we cannot instrument them.

@soldair soldair closed this as completed Feb 12, 2019
@mrdulin
Copy link

mrdulin commented Jul 25, 2019

@soldair

It seems trace agent really doesn't support webpack, but it supports typescript compiler. I have tested it. Here is the repo:
https://github.com/mrdulin/nodejs-gcp/tree/master/src/stackdriver/trace/webpacked-server-code

So, if I use typescript as my server-side code and I want to use trace agent. I can't use webpack or bundlers to compile my code? The suggestion is to use typescript compiler?

@kjin
Copy link
Contributor

kjin commented Jul 25, 2019

Ultimately what is preventing us from working with transpiled code is whether require is re-implemented as part of the transpilation. TypeScript outputs require statements with no modification to its implementation, while AFAIK webpack will re-define require to reference other blocks of code in the same code, which violates our current assumption that it is the require that Node provides us.

@mrdulin
Copy link

mrdulin commented Jul 26, 2019

@kjin Thanks for explaining. I have to choose TypeScript compiler instead of choosing webpack.

And I want to know do you have any plans for supporting webpack? Or, it's an impossible feature?

@kjin
Copy link
Contributor

kjin commented Jul 26, 2019

I would not expect TypeScript and webpack are not mutually exclusive, as they have fairly different purposes. That being said, unfortunately, we have no plans to support webpack, apologies for that!

@ghost
Copy link

ghost commented Oct 12, 2021

Any updates on this? Is webpack support on your roadmap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. web
Projects
None yet
Development

No branches or pull requests

6 participants