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

feat: add OpenTelemetry tracing #1182

Merged
merged 8 commits into from
Nov 22, 2023
Merged

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Nov 12, 2023

Adds OpenTelemetry tracing and configures Google Cloud Trace exports.

Adds OpenTelemetry tracing and metrics, and configures Google Cloud Trace
and Google Cloud Monitoring exports.
Copy link

codecov bot commented Nov 12, 2023

Codecov Report

Attention: 89 lines in your changes are missing coverage. Please review.

Comparison is base (397f1a2) 90.53% compared to head (7aa87f2) 89.95%.
Report is 4 commits behind head on postgresql-dialect.

Files Patch % Lines
...ava/com/google/cloud/spanner/pgadapter/Server.java 0.00% 49 Missing ⚠️
...ud/spanner/pgadapter/metadata/OptionsMetadata.java 21.05% 27 Missing and 3 partials ⚠️
...panner/pgadapter/statements/BackendConnection.java 92.68% 6 Missing and 3 partials ⚠️
...ner/pgadapter/statements/SimpleQueryStatement.java 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##             postgresql-dialect    #1182      +/-   ##
========================================================
- Coverage                 90.53%   89.95%   -0.58%     
- Complexity                 2561     2587      +26     
========================================================
  Files                       141      141              
  Lines                      8652     8874     +222     
  Branches                   1263     1285      +22     
========================================================
+ Hits                       7833     7983     +150     
- Misses                      557      622      +65     
- Partials                    262      269       +7     
Flag Coverage Δ
all_tests 89.95% <72.18%> (-0.58%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@olavloite olavloite marked this pull request as ready for review November 14, 2023 08:29
Copy link

@KiranmayiB KiranmayiB left a comment

Choose a reason for hiding this comment

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

Can you please link me to the guide you used for Otel integration?
It looks very different from https://opentelemetry.io/docs/instrumentation/java/manual/


In addition, PGAdapter always adds an exporter for Google Cloud Trace.

## Traces

Choose a reason for hiding this comment

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

Can you please add examples for metrics also here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't add any metrics in this pull request, only traces.

Choose a reason for hiding this comment

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

Alright sounds good then. Thanks!

server.startServer();
} catch (Exception e) {
printError(e, System.err, System.out);
}
}

static OpenTelemetry setupOpenTelemetry(OptionsMetadata optionsMetadata) throws IOException {
if (!optionsMetadata.isEnableOpenTelemetry()) {
return OpenTelemetry.noop();

Choose a reason for hiding this comment

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

Why is this noop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Returning a noop OpenTelemetry instance instead of null when OpenTelemetry has not been enabled makes the rest of the code simpler, as we don't need null checks everywhere.

Choose a reason for hiding this comment

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

Thanks!

@@ -218,6 +222,20 @@ public Builder setRequireAuthentication() {
return this;
}

/** Enables OpenTelemetry tracing for PGAdapter. */
public Builder setEnableOpenTelemetry() {

Choose a reason for hiding this comment

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

We are planning to make the Otel metrics in the client library as opt-in by default. So i think we should make this also as opt-out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What exactly do you mean by opt-in by default. Does that mean that you will enable it by default? If so, what exactly do you mean with enabled by default?

  1. Does it mean 'we enable OpenTelemetry by default, but we don't by default add any exporters'? If so, I would argue that this is still the same as the feature being an opt-in, as you still need to add an exporter before you actually collect any metrics.
  2. Or does it mean that we enable both OpenTelemetry and add an exporter (e.g. Google Cloud Tracer) by default? That would mean that we by default enable a feature that could incur additional costs for the customer. Is that intentional?

Choose a reason for hiding this comment

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

I meant the latter. But I realize now that itsn not possible for traces as we cannot specify a namespace. So lets leave this as-is. Thank you!

@olavloite
Copy link
Collaborator Author

https://opentelemetry.io/docs/instrumentation/java/manual/

This setup uses the OpenTelemetry automatic configuration module: https://opentelemetry.io/docs/instrumentation/java/manual/#automatic-configuration

The reason for this is that PGAdapter is mostly used as a standalone application, and not as a library. That means that configuration must happen on the command line when starting the application, instead of programmatic configuration that would be logical in a library (e.g. the Java client). The reasoning here is:

  1. We need command line configuration, as PGAdapter is mostly used as a standalone application, and not as an in-process dependency (which by the way is also possible, but less frequently used).
  2. Instead of re-inventing the wheel and adding a lot of command line arguments to PGAdapter, we use the library offered by OpenTelemetry to do command line configuration (in this case through Java System properties and/or Environment variables).
  3. We override the defaults of OpenTelemetry if the user has not specified any exporters. The default in the automatic configuration module of OpenTelemetry is to use the oltp exporter (see https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#exporters). That requires an OpenTelemetry endpoint, which we by default do not have. Instead, we set the default exporter that is used by the auto-configuration module to none, but allow the user to specify one using a system property or environment variable.
  4. In addition, we by default add a Google Trace exporter if OpenTelemetry has been enabled.

Copy link

@KiranmayiB KiranmayiB left a comment

Choose a reason for hiding this comment

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

Otel integration LGTM. Thanks a lot!

@olavloite olavloite changed the title feat: add OpenTelementry tracing and metrics feat: add OpenTelemetry tracing Nov 22, 2023
@olavloite olavloite merged commit 26217a3 into postgresql-dialect Nov 22, 2023
30 of 32 checks passed
@olavloite olavloite deleted the open-telemetry branch November 22, 2023 16:37
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