Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IDs Generator as Configurable Property of Auto Instrumentation #1404

Merged
merged 6 commits into from
Nov 24, 2020

Conversation

NathanielRN
Copy link
Contributor

Description

As a follow up to #1036, this PR adds a parameter to the opentelemetry-instrument executable to allow the IDs Generator to be configurable.

This is a necessary part for auto instrumentation with backends which need custom IDs, because once the opentelemetry-instrument executable sets up the TracerProvider, it is too late for the instrumented downstream application to configure the IDs.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@NathanielRN NathanielRN requested review from a team, toumorokoshi and lzchen and removed request for a team November 20, 2020 19:22
@NathanielRN
Copy link
Contributor Author

@owais Would appreciate your quick review on this so that we can have this functionality on the next release! Follow up to owais#1

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Thanks! This is great.

A couple small changes, but looking really good!

@@ -47,6 +47,19 @@ def parse_args():
""",
)

parser.add_argument(
"-g",
Copy link
Member

Choose a reason for hiding this comment

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

do we need a shortflag? IMO it's better to keep those to more general configuration, like version, help, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I agree with you! I had a hard time thinking of a letter, and so I don't think it'll be as easy to use as I had hoped, will use just the long version.

ids_generator_impl = None

for id_generator in iter_entry_points("opentelemetry_ids_generator"):
if id_generator.name == ids_generator_name.strip():
Copy link
Member

Choose a reason for hiding this comment

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

why deviate from the behavior of the exporters and perform a strip on the passed generator name?

Although it helps in a rare handful of cases, I think it's better to just perform no mutation on user input.

Alternatively, exporter and ids_generator should have the same mutation: strip both or strip none. It's minor, but the most confusing thing to a user is inconsistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually under the impression that exporter did strip the value:

Either way I think stripping the value is a good idea, I would expect

opentelemetry-instrument --ids-generator aws_xray

and

opentelemetry-instrument --ids-generator    aws_xray       

to work the same. But not sure if my second example would have whitespace to begin with 😅

@patch.dict(
environ, {"OTEL_SERVICE_NAME": "my-random-ids-generator-test-service"}
)
def test_trace_init_default_random_ids_generator(self):
Copy link
Member

Choose a reason for hiding this comment

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

is it worth testing the environment variable configuring the ids_generator?

If you don't, there's a risk that someone may modify that code to not work, and we'd have no way of validating programmatically.

Copy link
Contributor Author

@NathanielRN NathanielRN Nov 21, 2020

Choose a reason for hiding this comment

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

Yes it is worth it, I was just unfamiliar with how to do so but I agree it's worth it :) I've spent quite some time learning how to do it and finally figured out how to add it because I also think it's a useful add! Please let me know what you think!

self.assertIsInstance(provider, Provider)
self.assertIsInstance(provider.ids_generator, RandomIdsGenerator)
self.assertIsInstance(provider.processor, Processor)
self.assertIsInstance(provider.processor.exporter, OTLPExporter)
Copy link
Member

Choose a reason for hiding this comment

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

why verify things like the exporter, processor, provider? It's a bit harder to see what this test is trying to verify, when you include assertions for things that aren't related.

I'd argue if you are worried about those, they should be split out into smaller tests. It helps future developers more quickly find what behavior has regressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can go either way with this, I think it's useful to know that in a test where "I changed only one thing" the other parts of the functionality here still work.

However cleanliness is nice if I remove the rest of the checks, so I have removed them!

@NathanielRN NathanielRN force-pushed the otlp-env-config branch 2 times, most recently from 9401751 to 70e885f Compare November 21, 2020 10:12
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Looks good, only question i have is non-blocking

@@ -70,6 +82,8 @@ def load_config_from_cli_args(args):
environ["OTEL_EXPORTER"] = args.exporter
if args.service_name:
environ["OTEL_SERVICE_NAME"] = args.service_name
if args.ids_generator:
environ["OTEL_IDS_GENERATOR"] = args.ids_generator
Copy link
Contributor

Choose a reason for hiding this comment

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

there should be a proposal to the spec around this env variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will follow up with this soon!

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@codeboten codeboten merged commit da7597c into open-telemetry:master Nov 24, 2020
@NathanielRN NathanielRN deleted the otlp-env-config branch November 25, 2020 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants