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

Implement AwsSpanMetricsProcessor and MetricsAttributeGenerator #8

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

thpierce
Copy link
Contributor

@thpierce thpierce commented Jan 9, 2024

In this commit, we are implementing AwsSpanMetricsProcessor and AwsSpanMetricsProcessorBuilder. We needed to also implement the MetricsAttributeGenerator interface, since it is a dependency of AwsSpanMetricsProcessor, and we needed to implement a stub for AwsMetricsAttributeGenerator, since it is a dependency of AwsSpanMetricsProcessorBuilder. As much as possible, we are attempting to mirror the implementation of these clases found in https://github.com/aws-observability/aws-otel-java-instrumentation

General

  • SpanData: SpanData is used in Java impl as ReadableSpan does not let us access required information, but in Python, ReadableSpan is fully accessible and in fact SpanData is not even offered. As such, we make use only of ReadableSpan.
  • Histogram: In Java, there is a distinction between Double and Long Histograms, but Python only offers the base "Histogram", which supports floats.
  • @staticmethod vs # pylint: disable=no-self-use vs module method - The google style guide recommends against @staticmethod, but I have used it in MetricAttributeGenerator as I don't see a good way to have a static class and inheritance. # pylint: disable=no-self-use is used in AwsSpanMetricsProcessor to maintain overridden, inherited methods. Otherwise, I've tried to use module methods where possible.

AwsMetricAttributeGenerator

Methods:

  • Java-Python Mapping:
    • generateMetricAttributeMapFromSpan - See generate_metric_attributes_dict_from_span - Note that this will be properly implemented in next PR.

AwsSpanMetricsProcessor

Constants:

  • NANOS_TO_MILLIS - See _NANOS_TO_MILLIS
  • ERROR_CODE_LOWER_BOUND - See _ERROR_CODE_LOWER_BOUND
  • ERROR_CODE_UPPER_BOUND - See _ERROR_CODE_UPPER_BOUND
  • FAULT_CODE_LOWER_BOUND - See _FAULT_CODE_LOWER_BOUND
  • FAULT_CODE_UPPER_BOUND - See _FAULT_CODE_UPPER_BOUND

Methods:

  • Java-Python Mapping:
    • AwsSpanMetricsProcessor - See __init__
    • onStart - See on_start
    • onEnd - See on_end
    • recordErrorOrFault - See _record_metrics
    • recordLatency - See _record_error_or_fault
    • recordMetrics - See _record_latency
  • Java-only:
    • create - Not required, python doesn't have the concept of private methods/constructors, so it's not meaningful to abstract instantiation into a helper.
    • isStartRequired - Not part of SpanProcessor interface in Python.
    • isEndRequired - Not part of SpanProcessor interface in Python.
  • Python-only
    • shutdown - Part of SpanProcessor interface. In Java, default implementations are provided, not so in Python. Impl matches Java behaviour (no-op).
    • force_flush - Part of SpanProcessor interface. In Java, default implementations are provided, not so in Python. Impl matches Java behaviour (no-op).

AwsSpanMetricsProcessorBuilder

Constants:

  • ERROR - See _ERROR
  • FAULT - See _FAULT
  • LATENCY - See _LATENCY
  • LATENCY_UNITS - See _LATENCY_UNITS
  • DEFAULT_GENERATOR - See _DEFAULT_GENERATOR
  • DEFAULT_SCOPE_NAME - See _DEFAULT_SCOPE_NAME

Methods:

  • Java-Python Mapping:
    • AwsSpanMetricsProcessorBuilder - See __init__
    • setGenerator - See set_generator
    • setScopeName - See set_scope_name
    • build - See build
  • Java-only:
    • create - Not required, python doesn't have the concept of private methods/constructors, so it's not meaningful to abstract instantiation into a helper.

MetricAttributeGenerator

Constants:

  • SERVICE_METRIC - See _SERVICE_METRIC
  • DEPENDENCY_METRIC - See _DEPENDENCY_METRIC

Methods:

  • Java-Python Mapping:
    • generateMetricAttributeMapFromSpan - See generate_metric_attributes_dict_from_span

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@thpierce thpierce requested a review from a team January 9, 2024 19:57
@thpierce thpierce force-pushed the spm branch 3 times, most recently from 81b37fb to e9268d2 Compare January 9, 2024 22:03
In this commit, we are implementing AwsSpanMetricsProcessor and AwsSpanMetricsProcessorBuilder. We needed to also implement the MetricsAttributeGenerator interface, since it is a dependency of AwsSpanMetricsProcessor, and we needed to implement a stub for AwsMetricsAttributeGenerator, since it is a dependency of AwsSpanMetricsProcessorBuilder. As much as possible, we are attempting to mirror the implementation of these clases found in https://github.com/aws-observability/aws-otel-java-instrumentation
@thpierce thpierce changed the title TEMP PR - Add Span Metrics Processor and MetricAttributeGenerator interface Implement AwsSpanMetricsProcessor and MetricsAttributeGenerator Jan 9, 2024
@zzhlogin
Copy link
Contributor

zzhlogin commented Jan 9, 2024

  • recordErrorOrFault - See _record_metrics
  • recordLatency - See _record_error_or_fault
  • recordMetrics - See _record_latency
    Mismatch here?

Copy link
Contributor

@zzhlogin zzhlogin left a comment

Choose a reason for hiding this comment

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

Do we want some unit tests for the class implemented?
Shall we add the AwsSpanMetricsProcessor into AwsTracerProvider using self.add_span_processor()?

@thpierce
Copy link
Contributor Author

thpierce commented Jan 9, 2024

Do we want some unit tests for the class implemented?

No, unit tests will be a fast follow. We only added tests to TracerProvider/Configurator as they are the lowest-level classes and we want to make sure they built correctly.

Shall we add the AwsSpanMetricsProcessor into AwsTracerProvider using self.add_span_processor()?

Will do in a followup PR.

@thpierce thpierce merged commit 51c9ec0 into main Jan 10, 2024
16 checks passed
@thpierce thpierce deleted the spm branch January 10, 2024 17:02
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.

2 participants