Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Object Trace Exporter for programatic span access #564

Merged

Conversation

hekike
Copy link
Contributor

@hekike hekike commented May 29, 2019

I'm considering to use an in-memory exporter approach for unit testing.
This PR adds an object-exporter that stores started, ended and published spans in memory and makes them accessible.

[![Gitter chat][gitter-image]][gitter-url]

OpenCensus Object Trace Exporter allows the user to collect and
programatically access traces with [OpenCensus Node.js](https://github.com/census-instrumentation/opencensus-node). This module is useful for when you need
Copy link
Member

Choose a reason for hiding this comment

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

typo: s/programatically/programmatically/g

{
"name": "@opencensus/exporter-object",
"version": "0.0.13",
"description": "OpenCensus Object Exporter allows the user to collect and access traces with OpenCensus Node.js.",
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to publish this package to npm? If no, can we add private: true?

Copy link
Member

Choose a reason for hiding this comment

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

Because looks like real use case is for unit testing only, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could a developer consume it without npm? I'd expect it will be installed as a dev dependency.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. I thought, intention was to use in this project only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, sorry for not explaining the context well. I meant testing instrumentation in external services, My use case is that I instrumented an application with OpenCensus and now I want to be sure it collects the right spans during the application lifecycle. I could stub on Tracer internals but I feel it would be a cleaner approach.


import {CoreTracer, Span, SpanKind, TracerConfig} from '@opencensus/core';
import * as assert from 'assert';

Copy link
Member

Choose a reason for hiding this comment

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

Optional: remove the extra space


/** Object Exporter manager class */
export class ObjectTraceExporter implements Exporter {
buffer: ExporterBuffer;
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a private?

Copy link
Member

Choose a reason for hiding this comment

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

To fix the build either make this variable public or remove check on buffer queue length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Build fixed.

*/
onEndSpan(span: Span) {
this.endedSpans.push(span);
this.buffer.addToBuffer(span);
Copy link
Member

Choose a reason for hiding this comment

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

Just curious to know the usage of buffer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm missing something from how OpenCensus works. I thought core module calls publish with buffer content externally. Am I correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, correct. Earlier, I didn't understand the context well, thanks for explaining #564 (comment). Ignore this comment.

@codecov-io
Copy link

Codecov Report

Merging #564 into master will decrease coverage by 0.09%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #564     +/-   ##
=========================================
- Coverage    95.3%   95.21%   -0.1%     
=========================================
  Files         148      149      +1     
  Lines       10590    10510     -80     
  Branches      745      743      -2     
=========================================
- Hits        10093    10007     -86     
- Misses        497      503      +6
Impacted Files Coverage Δ
src/detect-resource.ts 66.66% <0%> (-24.25%) ⬇️
test/test-detect-resource.ts 93.93% <0%> (-5.09%) ⬇️
src/stackdriver-monitoring.ts 77.02% <0%> (-2.71%) ⬇️
src/resource-labels.ts 100% <0%> (ø) ⬆️
src/validators.ts 100% <0%> (ø) ⬆️
src/constants.ts
test/test-object.ts 95.77% <0%> (ø)
src/object.ts 96% <0%> (ø)
test/test-tracecontext-format.ts 97.36% <0%> (+2.01%) ⬆️
src/tracecontext-format.ts 97.43% <0%> (+3.2%) ⬆️

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 20e4cf0...6294e9b. Read the comment docs.

@mayurkale22 mayurkale22 merged commit 303c4ca into census-instrumentation:master Jun 3, 2019
@mayurkale22
Copy link
Member

@hekike https://www.npmjs.com/package/@opencensus/exporter-object is avaiable in npm after latest release (0.0.14).

@hekike
Copy link
Contributor Author

hekike commented Jun 4, 2019

Thank you!

@hekike hekike deleted the feat/exporter-object branch June 4, 2019 18:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants