zipkin-js icon indicating copy to clipboard operation
zipkin-js copied to clipboard

Can't resolve child_process error when importing CLSContext in angular application

Open moralce opened this issue 7 years ago • 3 comments

npm v4.6.1 node v8.9.4

To reproduce:

  • Create angular application using angular-cli
  • Add zipkin npm dependencies
  • Try to use zipkin by importing CLSContext in app.component.ts

This

import { Component } from '@angular/core';
import {ExplicitContext, Tracer, TraceId, HttpHeaders, BatchRecorder, jsonEncoder} from 'zipkin';
import {CLSContext} from 'zipkin-context-cls';
import {HttpLogger} from 'zipkin-transport-http'; 


const tracer = new Tracer({
    ctxImpl: new CLSContext('zipkin'),
    recorder: new BatchRecorder({
        logger: new HttpLogger({ endpoint: 'http://localhost:9411/api/v2/spans', jsonEncoder: jsonEncoder.JSON_V2 })
    }),
    localServiceName: 'angular-app' // name of this application
});

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
}

Produces the following error:

ERROR in ./node_modules/async-listener/index.js
Module not found: Error: Can't resolve 'child_process' in 'C:\zipkin-test\node_modules\async-listener'
ERROR in ./node_modules/async-listener/index.js
Module not found: Error: Can't resolve 'dns' in 'C:\zipkin-test\node_modules\async-listener'`

Using ctxImpl: new ExplicitContext(), instead fixes the issue.

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "types": ["node"],
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

package.json

{
  "name": "zipkin-test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "async-listener": "latest",
    "browser-process-hrtime": "^0.1.2",
    "child-process-async": "^1.0.1",
    "core-js": "^2.4.1",
    "express": "^4.14.0",
    "rest": "^1.3.2",
    "rxjs": "^5.5.2",
    "zipkin": "^0.11.1",
    "zipkin-context-cls": "^0.11.0",
    "zipkin-instrumentation-cujojs-rest": "^0.11.1",
    "zipkin-instrumentation-express": "^0.11.1",
    "zipkin-instrumentation-fetch": "^0.11.1",
    "zipkin-transport-http": "^0.11.1"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2",
    "browserify": "^14.1.0",
    "eslint": "^3.4.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.2.0"
  }
}

moralce avatar Feb 27 '18 10:02 moralce

this might not be relevant, so don't anchor your brain to it, too much https://github.com/othiym23/node-continuation-local-storage/issues/36

codefromthecrypt avatar Feb 28 '18 00:02 codefromthecrypt

Hi @moralce is this still an issue? If so, would you be able to come up with a test case for this?

jcchavezs avatar Sep 14 '18 06:09 jcchavezs

I have an issue i'm trying to solve where ALL spans are being added to ONE trace even though they are all totally distinct spans. I was using ExpliitContext but thought i'd try ClsContext .. and i see this same error. Can someone explain what the difference is between the two, why wouldi one use Explicit vs. Cls? I need to fix my problem and I'm not sure if ExplicitContext is the problem so not sure how much time i want to spend trying to get ClsContext to work on client/browser side.. any suggestions

jeffthompson1971 avatar Nov 17 '19 18:11 jeffthompson1971