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

Add support for custom attributes #492

Merged

Conversation

mhdawson
Copy link
Contributor

Add support for custom attributes for http and https spans
Fixes: #490

I've marked as Work in progress WIP as I've not looked at the updates needed to add any required documentation and to add tests.

I'm away until May 8th so I won't get back to the docs and tests until then but I wanted to get this out so that people could review provide additional feedback.

I think it is in line with the recommendations in #490 and it seems to work based on my test app.

@mhdawson
Copy link
Contributor Author

This is a snippet of the code I used to validate/test out manually

  function customAttributeFunction(span, request, response) {
    console.log('called');
    console.log(span.kind);

    if (span.kind === 1) {
      span.addAttribute('custom attribute1', 'value1');
    } else {
      span.addAttribute('custom attribute2', 'value2');
    }
  }

  const exporter = new JaegerTraceExporter(jaegerOptions);
  const jaeger = new propagation.JaegerFormat();
  const tracer = tracing.registerExporter(exporter).start({
    propagation: jaeger,
    plugins: {
      'http': {
        module: '@opencensus/instrumentation-http',
        config: {
          applyCustomAttributesOnSpan: customAttributeFunction
        }
      },
      'https': {
        module: '@opencensus/instrumentation-https',
        config: {
          applyCustomAttributesOnSpan: customAttributeFunction
        }
      }
    }
  });

@mhdawson
Copy link
Contributor Author

See there are also existing test failures. I had compiled the modules locally with npm run compile but not at the top level.

@mhdawson
Copy link
Contributor Author

mhdawson commented Apr 26, 2019

Believe I have resolved the failures which are applicable. Failures on node6 seem unrelated to the changes in this PR.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I like the general structure of this. IMO, if we had tests it would LGTM.

@mayurkale22
Copy link
Member

Overall LGTM, please add unit tests and update the CHANGLOG.md

@mhdawson
Copy link
Contributor Author

mhdawson commented May 8, 2019

@mayurkale22 thanks for reviewing! Just back from holiday today. will try to add the unit tests late this week or early next.

@mhdawson
Copy link
Contributor Author

Added unit tests.

Next need to rebase and then update CHANGLOG.md as well. Hope to get to that tomorrow.

@mhdawson
Copy link
Contributor Author

Seems I have some fixup. Seems like npm test does not run all that npm run compile does even though it seems to run the linter and be able to run the tests...

@mhdawson
Copy link
Contributor Author

@mayurkale22 I might need a suggestion on this one:

 Type declaration of 'any' loses type-safety. Consider replacing it with a more precise type. (no-any)
lerna ERR!   42 |  */
lerna ERR!   43 | export interface CustomAttributeFunction {
lerna ERR! > 44 |   (span: Span, ...rest: any[]): void;
lerna ERR!      |                        ^
lerna ERR!   45 | }

I'd added the ...rest:any[] because the http plugin custom attribute function has additional parameters. I'm new to TypeScript so now quite sure how to work around this differently.

@mhdawson mhdawson force-pushed the aftersuggestions branch from 7fc2fed to b744c8f Compare May 16, 2019 15:44
@mhdawson
Copy link
Contributor Author

mhdawson commented May 16, 2019

@mayurkale22 I found that any is allowed through a comment for some other similar cases, did that for now. Just pushed an update that rebases and adds the changes to the CHANGELOG.md. Locally npm run check passed so I'm hoping it will be good in the the CI.

@codecov-io
Copy link

codecov-io commented May 16, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
- Coverage   95.15%   94.79%   -0.36%     
==========================================
  Files         147      150       +3     
  Lines        9861    10054     +193     
  Branches      541      744     +203     
==========================================
+ Hits         9383     9531     +148     
- Misses        478      523      +45
Impacted Files Coverage Δ
test/test-tracecontext-format.ts 95.45% <0%> (-3.46%) ⬇️
src/trace/model/no-record/no-record-span.ts 55.55% <0%> (-1.59%) ⬇️
src/tracecontext-format.ts 95% <0%> (-1.08%) ⬇️
...ages-frontend/page-handlers/tracez.page-handler.ts 60.81% <0%> (-0.31%) ⬇️
test/test-ioredis.ts 96.96% <0%> (-0.04%) ⬇️
test/test-http.ts 98.46% <0%> (-0.03%) ⬇️
src/index.ts 100% <0%> (ø) ⬆️
src/http-stats.ts 100% <0%> (ø) ⬆️
test/test-root-span.ts 100% <0%> (ø) ⬆️
src/metrics/gauges/gauge.ts 100% <0%> (ø) ⬆️
... and 62 more

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 26c232c...01448dc. Read the comment docs.

@mhdawson mhdawson force-pushed the aftersuggestions branch from b744c8f to 01448dc Compare May 16, 2019 18:10
@mhdawson
Copy link
Contributor Author

@mayurkale22 I think this should be ready to go now. Just let me know if you have things you'd like me to change or update.

@mayurkale22
Copy link
Member

@mhdawson Thanks for fixing the build, will review it today.

@mayurkale22 mayurkale22 added this to the Release 0.0.13 milestone May 16, 2019
@mayurkale22
Copy link
Member

Is it a good time to remove "WIP" from the title?

@mhdawson mhdawson changed the title WIP: Add support for custom attributes Add support for custom attributes May 16, 2019
Add support for custom attributes for http and https spans
Fixes: census-instrumentation#490
@mhdawson mhdawson force-pushed the aftersuggestions branch from 01448dc to 9c05fba Compare May 16, 2019 21:25
@mhdawson
Copy link
Contributor Author

@mayurkale22 thanks forgot about that. Pushed update that removes WIP.

@mayurkale22
Copy link
Member

You may want to see this #514, looks like we can achieve same using Tracer > defaultAttributes. WDYT?

@mhdawson
Copy link
Contributor Author

@mayurkale22 unless I'm missing something that just lets you add a set of default key/value pairs. The requirement we had was to to be able to pull additional attributes from the request/response or otherwise as opposed to a fixed set?

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Ok got you. Thanks for the explanation. LGTM.

@mayurkale22
Copy link
Member

If no other comments from @draffensperger, I will merge it later today and will be avaiable in next release (0.0.13).

@mayurkale22 mayurkale22 merged commit c85ca67 into census-instrumentation:master May 17, 2019
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.

Support Custom attributes in instrumentation
5 participants