Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "opentracing in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'opentracing' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

let clientCallback = (err, res, headers, body) => {
          assert.isNull(err);
          assert.equal(reporter.spans.length, 2);

          // the first span to be reported is the server span
          let serverSpan = reporter.spans[0];
          // the second span to be reported is the client span
          let clientSpan = reporter.spans[1];

          let serverSpanTags = {};
          serverSpanTags[opentracing.Tags.PEER_SERVICE] = 'echo';
          serverSpanTags[opentracing.Tags.SPAN_KIND] = opentracing.Tags.SPAN_KIND_RPC_SERVER;
          serverSpanTags['as'] = o.as;
          // TODO(oibe) the port for the client request ephemeral, and I don't know how to get it, or if I can.

          let clientSpanTags = {};
          clientSpanTags[opentracing.Tags.PEER_SERVICE] = 'server';
          clientSpanTags[opentracing.Tags.SPAN_KIND] = opentracing.Tags.SPAN_KIND_RPC_CLIENT;

          assert.isTrue(TestUtils.hasTags(serverSpan, serverSpanTags));
          assert.isTrue(TestUtils.hasTags(clientSpan, clientSpanTags));
          assert.equal(serverSpan.context().parentIdStr, clientSpan.context().spanIdStr);
          // If context exists then the following conditions are true
          // else the following conditons are false
          assert.equal(serverSpan.context().traceIdStr === originalSpan.context().traceIdStr, !!o.context);
          assert.equal(clientSpan.context().traceIdStr === originalSpan.context().traceIdStr, !!o.context);
    public executeCodeFixCommand(fileTextChanges: ts.FileTextChanges[], span = new Span()): Observable {
        if (fileTextChanges.length === 0) {
            return Observable.throw(new Error('No changes supplied for code fix command'))
        }

        return this.projectManager
            .ensureOwnFiles(span)
            .concat(
                Observable.defer(() => {
                    // Configuration lookup uses Windows paths, FileTextChanges uses unix paths. Convert to backslashes.
                    const unixFilePath = fileTextChanges[0].fileName
                    const firstChangedFile = /^[a-z]:\//i.test(unixFilePath)
                        ? unixFilePath.replace(/\//g, '\\')
                        : unixFilePath

                    const configuration = this.projectManager.getConfiguration(firstChangedFile)
                    configuration.ensureBasicFiles(span)
    public ensureBasicFiles(span = new Span()): void {
        if (this.ensuredBasicFiles) {
            return
        }

        this.init(span)

        const program = this.getProgram(span)
        if (!program) {
            return
        }

        // Add all global declaration files from the workspace and all declarations from the project
        for (const uri of this.fs.uris()) {
            const fileName = uri2path(uri)
            const unixPath = toUnixPath(fileName)
            if (isGlobalTSFile(unixPath) || this.isExpectedDeclarationFile(unixPath)) {
it('should start and finish span with https', async () => {
      // WARNING: nock doesn't work well with https instrumentation
      // create real request

      await request('https://risingstack.com')

      expect(cls.startChildSpan).to.be.calledWith(tracer, instrumentation.OPERATION_NAME, {
        tags: {
          [Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
          [Tags.HTTP_URL]: 'https://risingstack.com:443/',
          [Tags.HTTP_METHOD]: 'GET'
        }
      })
      expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_STATUS_CODE, 200)
      expect(mockChildSpan.finish).to.have.callCount(1)
    })
it('should have http_request_handler metrics', () => {
      const reporter = new PrometheusReporter({
        ignoreTags: {
          [Tags.HTTP_URL]: /bar/
        }
      })
      const tracer = new Tracer('my-service', [reporter])

      const span1 = tracer.startSpan('http_request')
      span1.setTag(Tags.HTTP_URL, 'http://127.0.0.1/foo')
      span1.setTag(Tags.HTTP_METHOD, 'GET')
      span1.setTag(Tags.HTTP_STATUS_CODE, 200)
      span1.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_RPC_SERVER)
      clock.tick(100)
      span1.finish()

      // will be ignored
      const span2 = tracer.startSpan('http_request')
      span2.setTag(Tags.HTTP_URL, 'http://127.0.0.1/bar')
      span2.setTag(Tags.HTTP_METHOD, 'GET')
      span2.setTag(Tags.HTTP_STATUS_CODE, 200)
      span2.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_RPC_SERVER)
      clock.tick(300)
      span2.finish()

      const labelStr1 = `parent_service="${PrometheusReporter.LABEL_PARENT_SERVICE_UNKNOWN}",name="http_request"`
      const labelStr2 = `parent_service="${PrometheusReporter.LABEL_PARENT_SERVICE_UNKNOWN}",method="GET",code="200"`

      expect(reporter.metrics()).to.be.equal(dedent`
it('should start and finish span', async () => {
      const query = 'SELECT 1 AS result'
      const result = await db.raw(query)

      expect(result[0]).to.be.eql([{ result: 1 }])

      expect(cls.startChildSpan).to.be.calledWith(tracer, `${instrumentation.OPERATION_NAME}_query`, {
        tags: {
          [Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
          [Tags.DB_TYPE]: instrumentation.DB_TYPE,
          [Tags.DB_STATEMENT]: query
        }
      })

      // FIXME: only with ../instrument.js tests together
      // expect(mockChildSpan.finish).to.have.callCount(1)
    })
it('should observe HTTP request metrics without parent', function () {
      // init
      const prometheusReporter = new PrometheusReporter()
      const httpRequestDurationSeconds = prometheusReporter._metricshttpRequestDurationSeconds()

      const metricsStub = {
        observe: this.sandbox.spy()
      }

      this.sandbox.stub(httpRequestDurationSeconds, 'labels').callsFake(() => metricsStub)

      // generate data
      const tracer = new Tracer('service')

      const span = tracer.startSpan('http_request')
      span.setTag(Tags.HTTP_METHOD, 'GET')
      span.setTag(Tags.HTTP_STATUS_CODE, 200)
      span.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_RPC_SERVER)
      clock.tick(100)
      span.finish()

      prometheusReporter.reportFinish(span)

      // assert
      expect(httpRequestDurationSeconds.labels).to.have.callCount(1)
      expect(httpRequestDurationSeconds.labels)
        .to.be.calledWith(PrometheusReporter.LABEL_PARENT_SERVICE_UNKNOWN, 'GET', 200)

      expect(metricsStub.observe).to.have.callCount(1)
      expect(metricsStub.observe).to.be.calledWith(0.1)
    })
it('should have http_request_handler metrics', () => {
      const reporter = new PrometheusReporter({
        ignoreTags: {
          [Tags.HTTP_URL]: /bar/
        }
      })
      const tracer = new Tracer('my-service', [reporter])

      const span1 = tracer.startSpan('http_request')
      span1.setTag(Tags.HTTP_URL, 'http://127.0.0.1/foo')
      span1.setTag(Tags.HTTP_METHOD, 'GET')
      span1.setTag(Tags.HTTP_STATUS_CODE, 200)
      span1.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_RPC_SERVER)
      clock.tick(100)
      span1.finish()

      // will be ignored
      const span2 = tracer.startSpan('http_request')
      span2.setTag(Tags.HTTP_URL, 'http://127.0.0.1/bar')
      span2.setTag(Tags.HTTP_METHOD, 'GET')
it('should skip operation metrics by tag value', function () {
      // init
      const prometheusReporter = new PrometheusReporter({
        ignoreTags: {
          [Tags.HTTP_URL]: /foo/
        }
      })
      const metricsOperationDurationSeconds = prometheusReporter._metricsOperationDurationSeconds()

      const metricsStub = {
        observe: this.sandbox.spy()
      }

      this.sandbox.stub(metricsOperationDurationSeconds, 'labels').callsFake(() => metricsStub)

      // generate data
      const tracer = new Tracer('service')

      const span = tracer.startSpan('my-operation')
      span.setTag(Tags.HTTP_URL, 'http://127.0.0.1/foo')
      clock.tick(100)
it('should start and finish span', async () => {
      const query = 'SELECT 1 AS result'
      const { rows } = await db.raw(query)

      expect(rows).to.be.eql([{ result: 1 }])

      expect(cls.startChildSpan).to.be.calledWith(tracer, `${instrumentation.OPERATION_NAME}_query`, {
        tags: {
          [Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
          [Tags.DB_TYPE]: instrumentation.DB_TYPE,
          [Tags.DB_STATEMENT]: query
        }
      })

      // FIXME: only with ../instrument.js tests together
      // expect(mockChildSpan.finish).to.have.callCount(1)
    })

Is your System Free of Underlying Vulnerabilities?
Find Out Now