How to use the @opencensus/core.SpanKind.CLIENT function in @opencensus/core

To help you get started, we’ve selected a few @opencensus/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VilledeMontreal / workit / packages / workit-camunda / sample / tasks / helloWorldTaskV2.ts View on Github external
public async execute(message: IMessage): Promise {
      const { properties } = message;

      console.log(`Executing task: ${properties.activityId} with the class HelloWorldTaskV2`);
      console.log(`${properties.bpmnProcessId}::${properties.processInstanceId} Servus!`);
      console.log(`version: ${properties.workflowDefinitionVersion}`);
      
      const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
      const tracer = tracerService.getTracer();
      const span = tracer.startChildSpan({ name: 'customSpan', kind: SpanKind.CLIENT });
      
      console.log();
      console.log('data:');
      console.log(response.data);
      // put your business logic here
      span.end();
      return Promise.resolve(message);
  }
}
github keymetrics / pm2-io-apm / src / census / plugins / http.ts View on Github external
}
        }

        const request: httpModule.ClientRequest =
            original.apply(this, arguments)

        if (plugin.isIgnored(origin + pathname, request, plugin.options.ignoreOutgoingUrls)) {
          return request
        }

        plugin.tracer.wrapEmitter(request)

        plugin.logger.debug('%s plugin outgoingRequest', plugin.moduleName)
        const traceOptions = {
          name: `${kind.toLowerCase()}-${(method || 'GET').toLowerCase()}`,
          kind: SpanKind.CLIENT
        }
        // Checks if this outgoing request is part of an operation by checking
        // if there is a current root span, if so, we create a child span. In
        // case there is no root span, this means that the outgoing request is
        // the first operation, therefore we create a root span.
        if (!plugin.tracer.currentRootSpan) {
          plugin.logger.debug('outgoingRequest starting a root span')
          return plugin.tracer.startRootSpan(
              traceOptions,
              plugin.getMakeRequestTraceFunction(request, options, plugin))
        } else {
          plugin.logger.debug('outgoingRequest starting a child span')
          const span = plugin.tracer.startChildSpan(
              traceOptions.name, traceOptions.kind)
          return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
              span)
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zipkin / src / zipkin.ts View on Github external
translateSpan(span: Span): TranslatedSpan {
    const spanTranslated: TranslatedSpan = {
      traceId: span.traceId,
      name: span.name,
      id: span.id,
      // Zipkin API for span kind only accept
      // (CLIENT|SERVER|PRODUCER|CONSUMER)
      kind: span.kind === SpanKind.CLIENT ? 'CLIENT' : 'SERVER',
      timestamp: span.startTime.getTime() * MICROS_PER_MILLI,
      duration: Math.round(span.duration * MICROS_PER_MILLI),
      debug: true,
      shared: !span.parentSpanId,
      localEndpoint: { serviceName: this.serviceName },
      tags: this.createTags(span.attributes, span.status),
      annotations: this.createAnnotations(span.annotations, span.messageEvents),
    };

    if (span.parentSpanId) {
      spanTranslated.parentId = span.parentSpanId;
    }
    return spanTranslated;
  }
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / ioredis.spec.ts View on Github external
tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: RootSpan) => {
        await client.del('test')
        assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
        rootSpan.end()
        assertSpan(rootSpanVerifier, `redis-del`, SpanKind.CLIENT,
          (span) => {
            return span.attributes.arguments === undefined
          })
        done()
      })
    })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / mysql2.spec.ts View on Github external
client.query(q, (err, result) => {
          assert.strictEqual(result[0]['1'], 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
          rootSpan.end()
          assert.ifError(err)
          assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.sql, q)
          assertSpan(rootSpanVerifier, 'mysql-query', SpanKind.CLIENT)
          done()
        })
      })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / mysql2.spec.ts View on Github external
conn.query(q, (err, result) => {
            assert.strictEqual(result[0]['1'], 1)
            assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
            rootSpan.end()
            assert.ifError(err)
            assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
            assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
            assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.sql, q)
            assertSpan(rootSpanVerifier, 'mysql-query', SpanKind.CLIENT)
            done()
          })
        })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / pg.spec.ts View on Github external
client.query(q, (err, result) => {
          assert.strictEqual(result.rows[0].value, 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
          rootSpan.end()
          assert.ifError(err)
          assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
          assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.query, q)
          assertSpan(rootSpanVerifier, 'pg-query', SpanKind.CLIENT)
          done()
        })
      })
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-http / src / http.ts View on Github external
static recordStats(kind: SpanKind, tags: TagMap, ms: number) {
    if (!plugin.stats) return;

    try {
      const measureList = [];
      switch (kind) {
        case SpanKind.CLIENT:
          measureList.push({
            measure: stats.HTTP_CLIENT_ROUNDTRIP_LATENCY,
            value: ms,
          });
          break;
        case SpanKind.SERVER:
          measureList.push({ measure: stats.HTTP_SERVER_LATENCY, value: ms });
          break;
        default:
          break;
      }
      plugin.stats.record(measureList, tags);
    } catch (ignore) {}
  }
github keymetrics / pm2-io-apm / src / census / plugins / mongodb.ts View on Github external
const resultHandler = typeof options === 'function' ? options : callback
        if (plugin.tracer.currentRootSpan && typeof resultHandler === 'function') {
          let type: string
          if (command.createIndexes) {
            type = 'createIndexes'
          } else if (command.findandmodify) {
            type = 'findAndModify'
          } else if (command.ismaster) {
            type = 'isMaster'
          } else if (command.count) {
            type = 'count'
          } else {
            type = 'command'
          }

          const span = plugin.tracer.startChildSpan(label, SpanKind.CLIENT)
          if (span === null) return original.apply(this, arguments)
          span.addAttribute('database', ns)
          span.addAttribute('type', type)

          if (plugin.options.detailedCommands === true) {
            span.addAttribute('command', JSON.stringify(command))
          }

          if (typeof options === 'function') {
            return original.call(this, ns, command, plugin.patchEnd(span, options))
          } else {
            return original.call(this, ns, command,
                options, plugin.patchEnd(span, callback))
          }
        }
github keymetrics / pm2-io-apm / src / census / plugins / mysql2.ts View on Github external
return function (...args: any[]) {
        const span = plugin.tracer.startChildSpan('mysql-query', SpanKind.CLIENT)
        if (span === null) return original.apply(this, arguments)
        const query = original.apply(this, arguments)

        span.addAttribute('sql', query.sql)
        if (plugin.options.detailedCommands === true && query.values) {
          span.addAttribute('values', query.values)
        }
        if (typeof query._callback === 'function') {
          query._callback = plugin.patchEnd(span, query._callback)
        } else {
          query.on('end', function () {
            span.end()
          })
        }
        return query
      }