From 53ca1dc066f86d19b798c1784254e82e6172e3da Mon Sep 17 00:00:00 2001 From: suranjay Date: Sun, 21 May 2023 13:00:55 +0530 Subject: [PATCH 01/38] Add request tracing framework Signed-off-by: suranjay --- server/build.gradle | 84 ++++++- server/licenses/kotlin-stdlib-1.6.20.jar.sha1 | 1 + server/licenses/kotlin-stdlib-LICENSE.txt | 202 +++++++++++++++ server/licenses/kotlin-stdlib-NOTICE.txt | 0 server/licenses/okhttp-4.10.0.jar.sha1 | 1 + server/licenses/okhttp-LICENSE.txt | 202 +++++++++++++++ server/licenses/okhttp-NOTICE.txt | 0 server/licenses/okio-jvm-3.0.0.jar.sha1 | 1 + server/licenses/okio-jvm-LICENSE.txt | 202 +++++++++++++++ server/licenses/okio-jvm-NOTICE.txt | 202 +++++++++++++++ .../opentelemetry-api-1.23.1.jar.sha1 | 1 + server/licenses/opentelemetry-api-LICENSE.txt | 202 +++++++++++++++ server/licenses/opentelemetry-api-NOTICE.txt | 0 ...entelemetry-api-logs-1.23.1-alpha.jar.sha1 | 1 + .../opentelemetry-api-logs-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-api-logs-NOTICE.txt | 0 .../opentelemetry-context-1.23.1.jar.sha1 | 1 + .../opentelemetry-context-LICENSE.txt | 202 +++++++++++++++ .../licenses/opentelemetry-context-NOTICE.txt | 0 ...ntelemetry-exporter-common-1.23.1.jar.sha1 | 1 + .../opentelemetry-exporter-common-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-exporter-common-NOTICE.txt | 0 ...pentelemetry-exporter-otlp-1.23.1.jar.sha1 | 1 + .../opentelemetry-exporter-otlp-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-exporter-otlp-NOTICE.txt | 0 ...metry-exporter-otlp-common-1.23.1.jar.sha1 | 1 + ...telemetry-exporter-otlp-common-LICENSE.txt | 202 +++++++++++++++ ...ntelemetry-exporter-otlp-common-NOTICE.txt | 0 .../opentelemetry-sdk-1.23.1.jar.sha1 | 1 + server/licenses/opentelemetry-sdk-LICENSE.txt | 202 +++++++++++++++ server/licenses/opentelemetry-sdk-NOTICE.txt | 0 .../opentelemetry-sdk-common-1.23.1.jar.sha1 | 1 + .../opentelemetry-sdk-common-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-sdk-common-NOTICE.txt | 0 ...entelemetry-sdk-logs-1.23.1-alpha.jar.sha1 | 1 + .../opentelemetry-sdk-logs-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-sdk-logs-NOTICE.txt | 0 .../opentelemetry-sdk-metrics-1.23.1.jar.sha1 | 1 + .../opentelemetry-sdk-metrics-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-sdk-metrics-NOTICE.txt | 0 .../opentelemetry-sdk-trace-1.23.1.jar.sha1 | 1 + .../opentelemetry-sdk-trace-LICENSE.txt | 202 +++++++++++++++ .../opentelemetry-sdk-trace-NOTICE.txt | 0 ...pentelemetry-semconv-1.23.1-alpha.jar.sha1 | 1 + .../opentelemetry-semconv-LICENSE.txt | 202 +++++++++++++++ .../licenses/opentelemetry-semconv-NOTICE.txt | 0 .../common/settings/ClusterSettings.java | 10 +- .../common/util/concurrent/ThreadContext.java | 17 ++ .../main/java/org/opensearch/node/Node.java | 7 + .../org/opensearch/tracing/DefaultTracer.java | 229 ++++++++++++++++++ .../java/org/opensearch/tracing/Level.java | 103 ++++++++ .../java/org/opensearch/tracing/NoopSpan.java | 45 ++++ .../org/opensearch/tracing/NoopTracer.java | 74 ++++++ .../java/org/opensearch/tracing/OSSpan.java | 54 +++++ .../tracing/OTelResourceProvider.java | 61 +++++ .../java/org/opensearch/tracing/Span.java | 33 +++ .../org/opensearch/tracing/SpanHolder.java | 37 +++ .../java/org/opensearch/tracing/Tracer.java | 80 ++++++ .../org/opensearch/tracing/TracerFactory.java | 100 ++++++++ .../opensearch/tracing/TracerSettings.java | 99 ++++++++ .../org/opensearch/tracing/TracerUtils.java | 74 ++++++ .../org/opensearch/tracing/package-info.java | 12 + .../org/opensearch/bootstrap/security.policy | 3 + .../tracing/DefaultTracerTests.java | 130 ++++++++++ .../org/opensearch/tracing/LevelTests.java | 28 +++ .../tracing/TracerFactoryTests.java | 61 +++++ .../opensearch/tracing/TracerUtilsTests.java | 60 +++++ 67 files changed, 4645 insertions(+), 3 deletions(-) create mode 100644 server/licenses/kotlin-stdlib-1.6.20.jar.sha1 create mode 100644 server/licenses/kotlin-stdlib-LICENSE.txt create mode 100644 server/licenses/kotlin-stdlib-NOTICE.txt create mode 100644 server/licenses/okhttp-4.10.0.jar.sha1 create mode 100644 server/licenses/okhttp-LICENSE.txt create mode 100644 server/licenses/okhttp-NOTICE.txt create mode 100644 server/licenses/okio-jvm-3.0.0.jar.sha1 create mode 100644 server/licenses/okio-jvm-LICENSE.txt create mode 100644 server/licenses/okio-jvm-NOTICE.txt create mode 100644 server/licenses/opentelemetry-api-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-api-LICENSE.txt create mode 100644 server/licenses/opentelemetry-api-NOTICE.txt create mode 100644 server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 create mode 100644 server/licenses/opentelemetry-api-logs-LICENSE.txt create mode 100644 server/licenses/opentelemetry-api-logs-NOTICE.txt create mode 100644 server/licenses/opentelemetry-context-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-context-LICENSE.txt create mode 100644 server/licenses/opentelemetry-context-NOTICE.txt create mode 100644 server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-exporter-common-LICENSE.txt create mode 100644 server/licenses/opentelemetry-exporter-common-NOTICE.txt create mode 100644 server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-exporter-otlp-LICENSE.txt create mode 100644 server/licenses/opentelemetry-exporter-otlp-NOTICE.txt create mode 100644 server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt create mode 100644 server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt create mode 100644 server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-sdk-LICENSE.txt create mode 100644 server/licenses/opentelemetry-sdk-NOTICE.txt create mode 100644 server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-sdk-common-LICENSE.txt create mode 100644 server/licenses/opentelemetry-sdk-common-NOTICE.txt create mode 100644 server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 create mode 100644 server/licenses/opentelemetry-sdk-logs-LICENSE.txt create mode 100644 server/licenses/opentelemetry-sdk-logs-NOTICE.txt create mode 100644 server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-sdk-metrics-LICENSE.txt create mode 100644 server/licenses/opentelemetry-sdk-metrics-NOTICE.txt create mode 100644 server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 create mode 100644 server/licenses/opentelemetry-sdk-trace-LICENSE.txt create mode 100644 server/licenses/opentelemetry-sdk-trace-NOTICE.txt create mode 100644 server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 create mode 100644 server/licenses/opentelemetry-semconv-LICENSE.txt create mode 100644 server/licenses/opentelemetry-semconv-NOTICE.txt create mode 100644 server/src/main/java/org/opensearch/tracing/DefaultTracer.java create mode 100644 server/src/main/java/org/opensearch/tracing/Level.java create mode 100644 server/src/main/java/org/opensearch/tracing/NoopSpan.java create mode 100644 server/src/main/java/org/opensearch/tracing/NoopTracer.java create mode 100644 server/src/main/java/org/opensearch/tracing/OSSpan.java create mode 100644 server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java create mode 100644 server/src/main/java/org/opensearch/tracing/Span.java create mode 100644 server/src/main/java/org/opensearch/tracing/SpanHolder.java create mode 100644 server/src/main/java/org/opensearch/tracing/Tracer.java create mode 100644 server/src/main/java/org/opensearch/tracing/TracerFactory.java create mode 100644 server/src/main/java/org/opensearch/tracing/TracerSettings.java create mode 100644 server/src/main/java/org/opensearch/tracing/TracerUtils.java create mode 100644 server/src/main/java/org/opensearch/tracing/package-info.java create mode 100644 server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java create mode 100644 server/src/test/java/org/opensearch/tracing/LevelTests.java create mode 100644 server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java create mode 100644 server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java diff --git a/server/build.gradle b/server/build.gradle index 36b6f465bd80b..eefc174b6a403 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -134,6 +134,23 @@ dependencies { // precentil ranks aggregation api 'org.hdrhistogram:HdrHistogram:2.1.12' + // opentelemetry + api 'io.opentelemetry:opentelemetry-api:1.23.1' + api 'io.opentelemetry:opentelemetry-context:1.23.1' + api 'io.opentelemetry:opentelemetry-sdk:1.23.1' + api 'io.opentelemetry:opentelemetry-sdk-common:1.23.1' + api 'io.opentelemetry:opentelemetry-sdk-metrics:1.23.1' + api 'io.opentelemetry:opentelemetry-sdk-trace:1.23.1' + api 'io.opentelemetry:opentelemetry-exporter-otlp:1.23.1' + api 'io.opentelemetry:opentelemetry-exporter-common:1.23.1' + api 'io.opentelemetry:opentelemetry-exporter-otlp-common:1.23.1' + api 'io.opentelemetry:opentelemetry-semconv:1.23.1-alpha' + api 'com.squareup.okhttp3:okhttp:4.10.0' + api 'org.jetbrains.kotlin:kotlin-stdlib:1.6.20' + api 'com.squareup.okio:okio-jvm:3.0.0' + api 'io.opentelemetry:opentelemetry-sdk-logs:1.23.1-alpha' + api 'io.opentelemetry:opentelemetry-api-logs:1.23.1-alpha' + // lucene spatial api "org.locationtech.spatial4j:spatial4j:${versions.spatial4j}", optional api "org.locationtech.jts:jts-core:${versions.jts}", optional @@ -333,7 +350,63 @@ tasks.named("thirdPartyAudit").configure { 'com.google.common.geometry.S2Projections', 'com.google.common.geometry.S2Point', 'com.google.common.geometry.S2$Metric', - 'com.google.common.geometry.S2LatLng' + 'com.google.common.geometry.S2LatLng', + + // from opentelemetry + 'android.net.http.X509TrustManagerExtensions', + 'android.net.ssl.SSLSockets', + 'android.os.Build$VERSION', + 'android.security.NetworkSecurityPolicy', + 'android.util.Log', + 'com.google.common.io.ByteStreams', + 'com.google.common.util.concurrent.FutureCallback', + 'com.google.common.util.concurrent.Futures', + 'com.google.common.util.concurrent.ListenableFuture', + 'com.google.common.util.concurrent.MoreExecutors', + 'io.grpc.CallOptions', + 'io.grpc.Channel', + 'io.grpc.ClientInterceptor', + 'io.grpc.ClientInterceptors', + 'io.grpc.Codec', + 'io.grpc.Codec$Identity', + 'io.grpc.Drainable', + 'io.grpc.KnownLength', + 'io.grpc.ManagedChannel', + 'io.grpc.ManagedChannelBuilder', + 'io.grpc.Metadata', + 'io.grpc.Metadata$Key', + 'io.grpc.MethodDescriptor', + 'io.grpc.MethodDescriptor$Builder', + 'io.grpc.MethodDescriptor$Marshaller', + 'io.grpc.MethodDescriptor$MethodType', + 'io.grpc.Status', + 'io.grpc.Status$Code', + 'io.grpc.netty.GrpcSslContexts', + 'io.grpc.netty.NettyChannelBuilder', + 'io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts', + 'io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder', + 'io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder', + 'io.grpc.okhttp.OkHttpChannelBuilder', + 'io.grpc.stub.AbstractFutureStub', + 'io.grpc.stub.AbstractStub', + 'io.grpc.stub.ClientCalls', + 'io.grpc.stub.MetadataUtils', + 'io.netty.handler.ssl.SslContextBuilder', + 'io.opentelemetry.api.events.EventEmitter', + 'io.opentelemetry.api.events.EventEmitterBuilder', + 'io.opentelemetry.api.events.EventEmitterProvider', + 'io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties', + 'io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider', + 'io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider', + 'org.bouncycastle.jsse.BCSSLParameters', + 'org.bouncycastle.jsse.BCSSLSocket', + 'org.conscrypt.Conscrypt', + 'org.conscrypt.Conscrypt$Version', + 'org.conscrypt.ConscryptHostnameVerifier', + 'org.openjsse.javax.net.ssl.SSLParameters', + 'org.openjsse.javax.net.ssl.SSLSocket' + + ) ignoreViolations( 'com.google.protobuf.MessageSchema', @@ -342,7 +415,14 @@ tasks.named("thirdPartyAudit").configure { 'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor', 'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor', 'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor', - 'com.google.protobuf.UnsafeUtil$MemoryAccessor' + 'com.google.protobuf.UnsafeUtil$MemoryAccessor', + + // from opentelemetry + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField', + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerIndexField', + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerLimitField', + 'io.opentelemetry.internal.shaded.jctools.util.UnsafeAccess', + 'io.opentelemetry.internal.shaded.jctools.util.UnsafeRefArrayAccess' ) } diff --git a/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 b/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 new file mode 100644 index 0000000000000..a26a3b6591dcf --- /dev/null +++ b/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 @@ -0,0 +1 @@ +6cedc143badbb4f1c6b7f5a340b04edff1743208 \ No newline at end of file diff --git a/server/licenses/kotlin-stdlib-LICENSE.txt b/server/licenses/kotlin-stdlib-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/kotlin-stdlib-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/kotlin-stdlib-NOTICE.txt b/server/licenses/kotlin-stdlib-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/okhttp-4.10.0.jar.sha1 b/server/licenses/okhttp-4.10.0.jar.sha1 new file mode 100644 index 0000000000000..7cd464ff3effb --- /dev/null +++ b/server/licenses/okhttp-4.10.0.jar.sha1 @@ -0,0 +1 @@ +cd63657ac15770ed1420647154c9f44645533bef \ No newline at end of file diff --git a/server/licenses/okhttp-LICENSE.txt b/server/licenses/okhttp-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/okhttp-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/okhttp-NOTICE.txt b/server/licenses/okhttp-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/okio-jvm-3.0.0.jar.sha1 b/server/licenses/okio-jvm-3.0.0.jar.sha1 new file mode 100644 index 0000000000000..b75b63ec015bd --- /dev/null +++ b/server/licenses/okio-jvm-3.0.0.jar.sha1 @@ -0,0 +1 @@ +0ab5a73fa2ccb4a36b0b5c69fe10b16d0255bcf8 \ No newline at end of file diff --git a/server/licenses/okio-jvm-LICENSE.txt b/server/licenses/okio-jvm-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/okio-jvm-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/okio-jvm-NOTICE.txt b/server/licenses/okio-jvm-NOTICE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/okio-jvm-NOTICE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-api-1.23.1.jar.sha1 b/server/licenses/opentelemetry-api-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..77da8b4517207 --- /dev/null +++ b/server/licenses/opentelemetry-api-1.23.1.jar.sha1 @@ -0,0 +1 @@ +5d32a15207c1ce0c6d18247c66074bc5f0f77aae \ No newline at end of file diff --git a/server/licenses/opentelemetry-api-LICENSE.txt b/server/licenses/opentelemetry-api-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-api-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-api-NOTICE.txt b/server/licenses/opentelemetry-api-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 b/server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 new file mode 100644 index 0000000000000..fd7b2fdb4090a --- /dev/null +++ b/server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 @@ -0,0 +1 @@ +bb1d7a60ba642d5b280c17825dae1642c04f0a9f \ No newline at end of file diff --git a/server/licenses/opentelemetry-api-logs-LICENSE.txt b/server/licenses/opentelemetry-api-logs-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-api-logs-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-api-logs-NOTICE.txt b/server/licenses/opentelemetry-api-logs-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-context-1.23.1.jar.sha1 b/server/licenses/opentelemetry-context-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..e561e76c5a557 --- /dev/null +++ b/server/licenses/opentelemetry-context-1.23.1.jar.sha1 @@ -0,0 +1 @@ +be63aa23ebc7fbf4f9aa46c03855e7c784a334fc \ No newline at end of file diff --git a/server/licenses/opentelemetry-context-LICENSE.txt b/server/licenses/opentelemetry-context-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-context-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-context-NOTICE.txt b/server/licenses/opentelemetry-context-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..3cf6f53767f58 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 @@ -0,0 +1 @@ +e1e68d1ce6b4661e3a10f36a4ae5f364b06b27ed \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-common-LICENSE.txt b/server/licenses/opentelemetry-exporter-common-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-common-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-common-NOTICE.txt b/server/licenses/opentelemetry-exporter-common-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..2ba5197454396 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 @@ -0,0 +1 @@ +39b79499dcedd4b662c60eecc2db03b1efbdd368 \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt b/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-otlp-NOTICE.txt b/server/licenses/opentelemetry-exporter-otlp-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..3ab5a1acf2bc6 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 @@ -0,0 +1 @@ +0b131ab306d726260a91ea437e7a65b1e31ef417 \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt b/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt b/server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 b/server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..d7f5d66e39393 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 @@ -0,0 +1 @@ +071ebe12b1f42d4ec5da0c46443211eea53678d7 \ No newline at end of file diff --git a/server/licenses/opentelemetry-sdk-LICENSE.txt b/server/licenses/opentelemetry-sdk-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-sdk-NOTICE.txt b/server/licenses/opentelemetry-sdk-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 b/server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..7622c3ba0db58 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 @@ -0,0 +1 @@ +0a4510bbeb832bb21973d70e7ee02bbd6d15a1ba \ No newline at end of file diff --git a/server/licenses/opentelemetry-sdk-common-LICENSE.txt b/server/licenses/opentelemetry-sdk-common-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-common-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-sdk-common-NOTICE.txt b/server/licenses/opentelemetry-sdk-common-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 b/server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 new file mode 100644 index 0000000000000..0779c8a26c02f --- /dev/null +++ b/server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 @@ -0,0 +1 @@ +51bd87aea57262134d1190903a98c4a4fe70a8ec \ No newline at end of file diff --git a/server/licenses/opentelemetry-sdk-logs-LICENSE.txt b/server/licenses/opentelemetry-sdk-logs-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-logs-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-sdk-logs-NOTICE.txt b/server/licenses/opentelemetry-sdk-logs-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 b/server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..db9ef241fcf05 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 @@ -0,0 +1 @@ +0d2810c28865811662e003752d432a18c9a9a274 \ No newline at end of file diff --git a/server/licenses/opentelemetry-sdk-metrics-LICENSE.txt b/server/licenses/opentelemetry-sdk-metrics-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-metrics-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-sdk-metrics-NOTICE.txt b/server/licenses/opentelemetry-sdk-metrics-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 b/server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 new file mode 100644 index 0000000000000..d839f9ced343e --- /dev/null +++ b/server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 @@ -0,0 +1 @@ +cf84c1593b0f142eb6713df19e31203970ad1883 \ No newline at end of file diff --git a/server/licenses/opentelemetry-sdk-trace-LICENSE.txt b/server/licenses/opentelemetry-sdk-trace-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-sdk-trace-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-sdk-trace-NOTICE.txt b/server/licenses/opentelemetry-sdk-trace-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 b/server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 new file mode 100644 index 0000000000000..eb8620961adbe --- /dev/null +++ b/server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 @@ -0,0 +1 @@ +e5fb9ca7332fca0be964cbbfd17b1987166c0c75 \ No newline at end of file diff --git a/server/licenses/opentelemetry-semconv-LICENSE.txt b/server/licenses/opentelemetry-semconv-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/server/licenses/opentelemetry-semconv-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/server/licenses/opentelemetry-semconv-NOTICE.txt b/server/licenses/opentelemetry-semconv-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index c12eb87ddbcb5..6db763ff148ce 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -51,6 +51,8 @@ import org.opensearch.tasks.TaskManager; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.tasks.consumer.TopNSearchTasksLogger; +import org.opensearch.tracing.TracerSettings; +import org.opensearch.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.opensearch.action.admin.indices.close.TransportCloseIndexAction; @@ -649,7 +651,13 @@ public void apply(Settings value, Settings current, Settings previous) { RemoteRefreshSegmentPressureSettings.MIN_CONSECUTIVE_FAILURES_LIMIT, RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_MOVING_AVERAGE_WINDOW_SIZE, RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_PER_SEC_MOVING_AVERAGE_WINDOW_SIZE, - RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE + RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE, + + // Settings related to Tracing framework + TracerSettings.TRACER_LEVEL_SETTING, + TracerSettings.TRACER_EXPORTER_DELAY_SETTING, + TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, + TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING ) ) ); diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 5b9a77c75dddb..5e81d130e7a22 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -44,6 +44,8 @@ import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; import org.opensearch.http.HttpTransportSettings; +import org.opensearch.tracing.SpanHolder; +import org.opensearch.tracing.TracerUtils; import org.opensearch.tasks.Task; import java.io.IOException; @@ -66,6 +68,7 @@ import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_COUNT; import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_SIZE; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; /** @@ -151,6 +154,13 @@ public StoredContext stashContext() { threadContextStruct = threadContextStruct.putTransient(TASK_ID, context.transientHeaders.get(TASK_ID)); } + if (context.transientHeaders.containsKey(CURRENT_SPAN)) { + threadContextStruct = threadContextStruct.putTransient( + CURRENT_SPAN, + new SpanHolder((SpanHolder) context.transientHeaders.get(CURRENT_SPAN)) + ); + } + threadLocal.set(threadContextStruct); return () -> { @@ -246,6 +256,11 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collectio } // this is the context when this method returns final ThreadContextStruct newContext = threadLocal.get(); + + if (newContext.transientHeaders.containsKey(CURRENT_SPAN)) { + newContext.transientHeaders.put(CURRENT_SPAN, new SpanHolder((SpanHolder) newContext.transientHeaders.get(CURRENT_SPAN))); + } + return () -> { if (preserveResponseHeaders && threadLocal.get() != newContext) { threadLocal.set(originalContext.putResponseHeaders(threadLocal.get().responseHeaders)); @@ -710,6 +725,8 @@ private ThreadContextStruct copyHeaders(Iterable> head } private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { + TracerUtils.addTracerContextToHeader(this.requestHeaders, this.transientHeaders); + final Map requestHeaders; if (defaultHeaders.isEmpty()) { requestHeaders = this.requestHeaders; diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index a25bac60f49b6..fd522b7a14c58 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -56,6 +56,7 @@ import org.opensearch.monitor.fs.FsProbe; import org.opensearch.plugins.ExtensionAwarePlugin; import org.opensearch.plugins.SearchPipelinePlugin; +import org.opensearch.tracing.TracerFactory; import org.opensearch.search.backpressure.SearchBackpressureService; import org.opensearch.search.backpressure.settings.SearchBackpressureSettings; import org.opensearch.search.pipeline.SearchPipelineService; @@ -63,6 +64,7 @@ import org.opensearch.tasks.consumer.TopNSearchTasksLogger; import org.opensearch.threadpool.RunnableTaskExecutionListener; import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory; +import org.opensearch.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.core.Assertions; import org.opensearch.Build; @@ -1008,6 +1010,10 @@ protected Node( searchModule.getIndexSearcherExecutor(threadPool) ); + final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); + TracerFactory.initTracerFactory(threadPool, tracerSettings); + resourcesToClose.add(TracerFactory::closeTracer); + final List> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class) .stream() .map( @@ -1465,6 +1471,7 @@ public synchronized void close() throws IOException { toClose.add(() -> stopWatch.stop().start("node_environment")); toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(stopWatch::stop); + toClose.add(TracerFactory::closeTracer); if (logger.isTraceEnabled()) { toClose.add(() -> logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint())); diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java new file mode 100644 index 0000000000000..ecaab906a5760 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java @@ -0,0 +1,229 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.context.Context; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.threadpool.ThreadPool; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Optional; + +/** + * + * The default tracer implementation. This class implements the basic logic for span lifecycle and its state management. + * It also handles tracing context propagation between spans. + * + * It internally uses OpenTelemetry tracer. + * + */ +public class DefaultTracer implements Tracer { + + public static final String CURRENT_SPAN = "current_span"; + + private static final Logger logger = LogManager.getLogger(DefaultTracer.class); + private static final String TRACE_ID = "trace_id"; + private static final String SPAN_ID = "span_id"; + private static final String SPAN_NAME = "span_name"; + private static final String PARENT_SPAN_ID = "p_span_id"; + private static final String THREAD_NAME = "th_name"; + private static final String PARENT_SPAN_NAME = "p_span_name"; + private static final String ROOT_SPAN = "RootSpan"; + + private final ThreadPool threadPool; + private final TracerSettings tracerSettings; + private final io.opentelemetry.api.trace.Tracer otelTracer; + private final OpenTelemetry openTelemetry; + + public DefaultTracer(OpenTelemetry openTelemetry, ThreadPool threadPool, TracerSettings tracerSettings) { + this.openTelemetry = openTelemetry; + this.otelTracer = openTelemetry.getTracer("os-tracer"); + this.threadPool = threadPool; + this.tracerSettings = tracerSettings; + } + + @Override + public void startSpan(String spanName, Level level) { + Span span = createSpan(spanName, getCurrentSpan(), level); + setCurrentSpanInContext(span); + setSpanAttributes(span); + } + + @Override + public void endSpan() { + Span currentSpan = getCurrentSpan(); + if (currentSpan != null) { + endSpan(currentSpan); + setCurrentSpanInContext(currentSpan.getParentSpan()); + } + } + + @Override + public void addAttribute(String key, String value) { + addSingleAttribute(AttributeKey.stringKey(key), value); + } + + @Override + public void addAttribute(String key, long value) { + addSingleAttribute(AttributeKey.longKey(key), value); + + } + + @Override + public void addAttribute(String key, double value) { + addSingleAttribute(AttributeKey.doubleKey(key), value); + } + + @Override + public void addAttribute(String key, boolean value) { + addSingleAttribute(AttributeKey.booleanKey(key), value); + } + + @Override + public void addEvent(String event) { + Span currentSpan = getCurrentSpan(); + if (currentSpan instanceof OSSpan && ((OSSpan) currentSpan).getOtelSpan() != null) { + ((OSSpan) currentSpan).getOtelSpan().addEvent(event); + } + } + + @Override + public void close() { + if (openTelemetry instanceof Closeable) { + try { + ((Closeable) openTelemetry).close(); + } catch (IOException e) { + logger.warn("Error while closing tracer", e); + } + } + } + + @Override + public Span getCurrentSpan() { + Optional optionalSpanFromContext = spanFromThreadContext(); + return optionalSpanFromContext.orElse(spanFromHeader()); + } + + private Span spanFromHeader() { + Context context = TracerUtils.extractTracerContextFromHeader(threadPool.getThreadContext().getHeaders()); + if (context != null) { + io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); + return new OSSpan(ROOT_SPAN, span, null, Level.ROOT); + } + return null; + } + + private Optional spanFromThreadContext() { + ThreadContext threadContext = threadPool.getThreadContext(); + SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); + + return (spanHolder == null) ? Optional.empty() : Optional.ofNullable(spanHolder.getSpan()); + } + + private Span createSpan(String spanName, Span parentSpan, Level level) { + return isLevelEnabled(level) ? createOSSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); + } + + private Span createOSSpan(String spanName, Span parentSpan, Level level) { + OSSpan parentOSSpan = getLastValidSpanInChain(parentSpan); + io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentOSSpan); + Span span = new OSSpan(spanName, otelSpan, parentSpan, level); + logger.debug( + "Starting OtelSpan spanId:{} name:{}: traceId:{}", + otelSpan.getSpanContext().getSpanId(), + span.getSpanName(), + otelSpan.getSpanContext().getTraceId() + ); + return span; + } + + private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { + logger.debug("Starting Noop span name:{}", spanName); + return new NoopSpan(spanName, parentSpan, level); + } + + private OSSpan getLastValidSpanInChain(Span parentSpan) { + while (parentSpan instanceof NoopSpan) { + parentSpan = parentSpan.getParentSpan(); + } + return (OSSpan) parentSpan; + } + + // visible for testing + io.opentelemetry.api.trace.Span createOtelSpan(String spanName, OSSpan parentOSSpan) { + return parentOSSpan == null + ? otelTracer.spanBuilder(spanName).startSpan() + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentOSSpan.getOtelSpan())).startSpan(); + } + + private boolean isLevelEnabled(Level level) { + Level configuredLevel = tracerSettings.getTracerLevel(); + return level.isHigher(configuredLevel); + } + + private void setCurrentSpanInContext(Span span) { + if (span == null) { + return; + } + ThreadContext threadContext = threadPool.getThreadContext(); + SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); + if (spanHolder == null) { + threadContext.putTransient(CURRENT_SPAN, new SpanHolder(span)); + } else { + spanHolder.setSpan(span); + } + } + + private void endSpan(Span span) { + if (span instanceof OSSpan && ((OSSpan) span).getOtelSpan() != null) { + OSSpan osSpan = (OSSpan) span; + logger.debug( + "Ending span spanId:{} name:{}: traceId:{}", + osSpan.getSpanContext().getSpanId(), + span.getSpanName(), + osSpan.getSpanContext().getTraceId() + ); + osSpan.getOtelSpan().end(); + } else { + logger.debug("Ending noop span name:{}", span.getSpanName()); + } + } + + private void setSpanAttributes(Span span) { + if (span instanceof OSSpan) { + addDefaultAttributes((OSSpan) span); + } + } + + private void addSingleAttribute(AttributeKey key, T value) { + Span currentSpan = getCurrentSpan(); + if (currentSpan instanceof OSSpan && ((OSSpan) currentSpan).getOtelSpan() != null) { + ((OSSpan) currentSpan).getOtelSpan().setAttribute(key, value); + } + } + + private void addDefaultAttributes(OSSpan osSpan) { + if (osSpan != null) { + addSingleAttribute(AttributeKey.stringKey(SPAN_ID), osSpan.getSpanContext().getSpanId()); + addSingleAttribute(AttributeKey.stringKey(TRACE_ID), osSpan.getSpanContext().getTraceId()); + addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), osSpan.getSpanName()); + addSingleAttribute(AttributeKey.stringKey(THREAD_NAME), Thread.currentThread().getName()); + if (osSpan.getParentSpan() != null && osSpan.getParentSpan() instanceof OSSpan) { + addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_ID), ((OSSpan) osSpan.getParentSpan()).getSpanContext().getSpanId()); + addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), osSpan.getParentSpan().getSpanName()); + } + } + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/Level.java b/server/src/main/java/org/opensearch/tracing/Level.java new file mode 100644 index 0000000000000..7e20483f1038d --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/Level.java @@ -0,0 +1,103 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.util.Arrays; + +/** + * The Level class defines a set of standard tracing levels that can be used to control tracing output. + * The tracing Level objects are ordered and are specified by ordered integers. + * Enabling tracing at a given level also enables tracing at all higher levels. + * + * Levels in descending order are + *
    + *
  • ROOT(highest value)
  • + *
  • TERSE
  • + *
  • INFO
  • + *
  • DEBUG
  • + *
  • TRACE(lowest value)
  • + *
+ * + * In addition, there is a level DISABLED that can be used to turn off tracing. By default, tracing is disabled. + * + */ +public enum Level { + /** + * DISABLED is a special level that can be used to turn off tracing. This level is initialized to Integer.MAX_VALUE. + */ + DISABLED(Integer.MAX_VALUE), + + /** + * ROOT is a tracing level indicating top level/root spans. + */ + ROOT(500), + + /** + * TERSE is a tracing level for critical spans + */ + TERSE(400), + + /** + * INFO is a tracing level used of generic spans + */ + INFO(300), + + /** + * DEBUG is a tracing level used for low level spans + */ + DEBUG(200), + + /** + * TRACE is the lowest level span + */ + TRACE(100); + + private final int value; + + Level(int value) { + this.value = value; + } + + /** + * Returns a mirrored Level object that matches the given name. Throws {@link IllegalArgumentException} if no match is found + * @param name string value + * @return Level corresponding to the given name + */ + public static Level fromString(String name) { + for (Level level : values()) { + if (level.name().equalsIgnoreCase(name)) { + return level; + } + } + throw new IllegalArgumentException( + "invalid value for tracing level [" + name + "], " + "must be in " + Arrays.asList(Level.values()) + ); + } + + /** + * Get the integer value for this level + * @return integer value of the level + */ + public int getValue() { + return value; + } + + /** + * Checks if the current level's value is higher than the given level + * @param level to compare + * @return true if the current level's value is higher than given level's value, false otherwise + */ + public boolean isHigher(Level level) { + if (level != null) { + return this.value >= level.value; + } + return false; + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/NoopSpan.java b/server/src/main/java/org/opensearch/tracing/NoopSpan.java new file mode 100644 index 0000000000000..fb7bc0f433654 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/NoopSpan.java @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * No-op implementation of Span + */ +class NoopSpan implements Span { + private static final Logger logger = LogManager.getLogger(NoopSpan.class); + + private final String spanName; + private final Span parentSpan; + private final Level level; + + public NoopSpan(String spanName, Span parentSpan, Level level) { + this.spanName = spanName; + this.parentSpan = parentSpan; + this.level = level; + } + + @Override + public Span getParentSpan() { + return parentSpan; + } + + @Override + public Level getLevel() { + return level; + } + + @Override + public String getSpanName() { + return spanName; + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/NoopTracer.java b/server/src/main/java/org/opensearch/tracing/NoopTracer.java new file mode 100644 index 0000000000000..b6f6a90026dba --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/NoopTracer.java @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +/** + * No-op implementation of Tracer + */ +class NoopTracer implements Tracer { + + @Override + public void startSpan(String spanName, Level level) { + + } + + @Override + public void endSpan() {} + + /** + * @param key attribute key + * @param value attribute value + */ + @Override + public void addAttribute(String key, String value) { + + } + + /** + * @param key attribute key + * @param value attribute value + */ + @Override + public void addAttribute(String key, long value) { + + } + + /** + * @param key attribute key + * @param value attribute value + */ + @Override + public void addAttribute(String key, double value) { + + } + + /** + * @param key attribute key + * @param value attribute value + */ + @Override + public void addAttribute(String key, boolean value) { + + } + + @Override + public void addEvent(String event) { + + } + + @Override + public Span getCurrentSpan() { + return null; + } + + @Override + public void close() { + + } +} diff --git a/server/src/main/java/org/opensearch/tracing/OSSpan.java b/server/src/main/java/org/opensearch/tracing/OSSpan.java new file mode 100644 index 0000000000000..d5b60799cef0c --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/OSSpan.java @@ -0,0 +1,54 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.trace.SpanContext; + +/** + * Default implementation of {@link Span}. It keeps a reference of OpenTelemetry Span and handles span + * lifecycle management by delegating calls to it. + */ +class OSSpan implements Span { + + private final String spanName; + private final io.opentelemetry.api.trace.Span otelSpan; + private final Span parentSpan; + private final Level level; + + public OSSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { + this.spanName = spanName; + this.otelSpan = span; + this.parentSpan = parentSpan; + this.level = level; + } + + @Override + public Span getParentSpan() { + return parentSpan; + } + + @Override + public Level getLevel() { + return level; + } + + @Override + public String getSpanName() { + return spanName; + } + + io.opentelemetry.api.trace.Span getOtelSpan() { + return otelSpan; + } + + SpanContext getSpanContext() { + return otelSpan.getSpanContext(); + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java b/server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java new file mode 100644 index 0000000000000..1eaedef88a912 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java @@ -0,0 +1,61 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; + +import java.util.concurrent.TimeUnit; + +/** + * This class encapsulates all OpenTelemetry related resources + */ +class OTelResourceProvider { + + private static final Resource resource; + private static final ContextPropagators contextPropagators; + private static volatile OpenTelemetry OPEN_TELEMETRY; + + static { + resource = Resource.getDefault().merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch"))); + contextPropagators = ContextPropagators.create(W3CTraceContextPropagator.getInstance()); + } + + static OpenTelemetry getOrCreateOpenTelemetryInstance(TracerSettings tracerSettings) { + if (OPEN_TELEMETRY == null) { + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor( + BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().setTimeout(10, TimeUnit.SECONDS).build()) + .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) + .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) + .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) + .build() + ) + .setResource(resource) + .build(); + OPEN_TELEMETRY = OpenTelemetrySdk.builder() + .setTracerProvider(sdkTracerProvider) + .setPropagators(contextPropagators) + .buildAndRegisterGlobal(); + } + return OPEN_TELEMETRY; + } + + static ContextPropagators getContextPropagators() { + return contextPropagators; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/Span.java b/server/src/main/java/org/opensearch/tracing/Span.java new file mode 100644 index 0000000000000..bf0ff1d43225b --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/Span.java @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +/** + * An interface that represents a tracing span. + * Spans are created by the Tracer.startSpan method. + * Span must be ended by calling Tracer.endSpan which internally calls Span's endSpan. + */ +public interface Span { + + /** + * Returns span's parent span + */ + Span getParentSpan(); + + /** + * Returns the name of the {@link Span} + */ + String getSpanName(); + + /** + * Returns {@link Level} of the {@link Span} + */ + Level getLevel(); + +} diff --git a/server/src/main/java/org/opensearch/tracing/SpanHolder.java b/server/src/main/java/org/opensearch/tracing/SpanHolder.java new file mode 100644 index 0000000000000..1166194f10895 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/SpanHolder.java @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.util.concurrent.atomic.AtomicReference; + +/** + * Mutable wrapper class to store {@link Span}. + */ +public class SpanHolder { + + private final AtomicReference span = new AtomicReference<>(); + + public SpanHolder(SpanHolder spanHolder) { + if (spanHolder != null) { + this.span.set(spanHolder.span.get()); + } + } + + public SpanHolder(Span span) { + this.span.set(span); + } + + public Span getSpan() { + return span.get(); + } + + public void setSpan(Span span) { + this.span.set(span); + } +} diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/server/src/main/java/org/opensearch/tracing/Tracer.java new file mode 100644 index 0000000000000..147d45f117654 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/Tracer.java @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.io.Closeable; + +/** + * Tracer is the interface used to create a {@link Span} and interact with current active {@link Span}. + * It automatically handles the context propagation between threads, tasks, nodes etc. + * + * All methods on the Tracer object are multi-thread safe. + */ +public interface Tracer extends Closeable { + + /** + * Starts the {@link Span} with given name and level + * + * @param spanName span name + * @param level span tracing level + */ + void startSpan(String spanName, Level level); + + /** + * Ends the current active {@link Span} + * + */ + void endSpan(); + + /** + * Returns the current active {@link Span} + * + * @return current active span + */ + Span getCurrentSpan(); + + /** + * Adds string attribute to the current active {@link Span}. + * + * @param key attribute key + * @param value attribute value + */ + void addAttribute(String key, String value); + + /** + * Adds long attribute to the current active {@link Span}. + * + * @param key attribute key + * @param value attribute value + */ + void addAttribute(String key, long value); + + /** + * Adds double attribute to the current active {@link Span}. + * + * @param key attribute key + * @param value attribute value + */ + void addAttribute(String key, double value); + + /** + * Adds boolean attribute to the current active {@link Span}. + * + * @param key attribute key + * @param value attribute value + */ + void addAttribute(String key, boolean value); + + /** + * Adds an event to the current active {@link Span}. + * + * @param event event name + */ + void addEvent(String event); +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/tracing/TracerFactory.java new file mode 100644 index 0000000000000..e36b46abb2a6a --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/TracerFactory.java @@ -0,0 +1,100 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.threadpool.ThreadPool; + +import java.io.IOException; + +/** + * TracerFactory represents a single global class that is used to access tracers. + * + * The Tracer singleton object can be retrieved using TracerFactory.getTracer(). The TracerFactory object + * is created during class initialization and cannot subsequently be changed. + */ +public class TracerFactory { + + private static final Logger logger = LogManager.getLogger(TracerFactory.class); + private static final Tracer noopTracer = new NoopTracer(); + private static volatile TracerFactory INSTANCE; + + private final ThreadPool threadPool; + private final TracerSettings tracerSettings; + private final Object mutex = new Object(); + private volatile Tracer defaultTracer; + + /** + * Initializes the TracerFactory singleton instance + * @param threadPool threadpool instance + * @param tracerSettings tracer settings instance + */ + public static synchronized void initTracerFactory(ThreadPool threadPool, TracerSettings tracerSettings) { + if (INSTANCE == null) { + INSTANCE = new TracerFactory(threadPool, tracerSettings); + } else { + logger.warn("Trying to double initialize TracerFactory, skipping"); + } + } + + /** + * Returns the {@link Tracer} singleton instance + * @return Tracer instance + */ + public static Tracer getTracer() { + return INSTANCE == null ? noopTracer : INSTANCE.tracer(); + } + + /** + * Closes the {@link Tracer} + */ + public static void closeTracer() { + if (INSTANCE != null && INSTANCE.defaultTracer != null) { + try { + INSTANCE.defaultTracer.close(); + } catch (IOException e) { + logger.warn("Error closing tracer", e); + } + } + } + + public TracerFactory(ThreadPool threadPool, TracerSettings tracerSettings) { + this.threadPool = threadPool; + this.tracerSettings = tracerSettings; + } + + private Tracer tracer() { + return isTracingDisabled() ? noopTracer : getOrCreateDefaultTracerInstance(); + } + + private boolean isTracingDisabled() { + return Level.DISABLED == tracerSettings.getTracerLevel(); + } + + private Tracer getOrCreateDefaultTracerInstance() { + if (defaultTracer == null) { + synchronized (mutex) { + if (defaultTracer == null) { + logger.info("Creating Otel tracer..."); + OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); + defaultTracer = new DefaultTracer(openTelemetry, threadPool, tracerSettings); + } + } + } + return defaultTracer; + } + + // for testing + static void clear() { + INSTANCE = null; + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerSettings.java b/server/src/main/java/org/opensearch/tracing/TracerSettings.java new file mode 100644 index 0000000000000..d595217039672 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/TracerSettings.java @@ -0,0 +1,99 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.unit.TimeValue; + +/** + * Wrapper class to encapsulate tracing related settings + */ +public class TracerSettings { + public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( + "tracer.exporter.batch_size", + 512, + 1, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( + "tracer.exporter.max_queue_size", + 2048, + 1, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( + "tracer.exporter.delay", + TimeValue.timeValueSeconds(2), + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + public static final Setting TRACER_LEVEL_SETTING = new Setting<>( + "tracer.level", + Level.DISABLED.name(), + Level::fromString, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + + private volatile Level tracerLevel; + + private volatile int exporterBatchSize; + + private volatile int exporterMaxQueueSize; + + private volatile TimeValue exporterDelay; + + public TracerSettings(Settings settings, ClusterSettings clusterSettings) { + this.tracerLevel = TRACER_LEVEL_SETTING.get(settings); + this.exporterBatchSize = TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings); + this.exporterMaxQueueSize = TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING.get(settings); + this.exporterDelay = TRACER_EXPORTER_DELAY_SETTING.get(settings); + + clusterSettings.addSettingsUpdateConsumer(TRACER_LEVEL_SETTING, this::setTracerLevel); + clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_BATCH_SIZE_SETTING, this::setExporterBatchSize); + clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, this::setExporterMaxQueueSize); + clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_DELAY_SETTING, this::setExporterDelay); + } + + public void setTracerLevel(Level tracerLevel) { + this.tracerLevel = tracerLevel; + } + + public void setExporterBatchSize(int exporterBatchSize) { + this.exporterBatchSize = exporterBatchSize; + } + + public void setExporterMaxQueueSize(int exporterMaxQueueSize) { + this.exporterMaxQueueSize = exporterMaxQueueSize; + } + + public void setExporterDelay(TimeValue exporterDelay) { + this.exporterDelay = exporterDelay; + } + + public Level getTracerLevel() { + return tracerLevel; + } + + public int getExporterBatchSize() { + return exporterBatchSize; + } + + public int getExporterMaxQueueSize() { + return exporterMaxQueueSize; + } + + public TimeValue getExporterDelay() { + return exporterDelay; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerUtils.java b/server/src/main/java/org/opensearch/tracing/TracerUtils.java new file mode 100644 index 0000000000000..3f1234088a1d3 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/TracerUtils.java @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.context.Context; +import io.opentelemetry.context.propagation.TextMapGetter; +import io.opentelemetry.context.propagation.TextMapSetter; + +import java.util.Map; + +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; + +/** + * Contains utils methods for tracing + */ +public class TracerUtils { + + private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { + if (carrier != null) { + carrier.put(key, value); + } + }; + + private static final TextMapGetter> TEXT_MAP_GETTER = new TextMapGetter<>() { + @Override + public Iterable keys(Map headers) { + return headers.keySet(); + } + + @Override + public String get(Map headers, String key) { + if (headers != null && headers.containsKey(key)) { + return headers.get(key); + } + return null; + } + }; + + /** + * Adds current active span as tracing context in the header during outbound calls + */ + public static void addTracerContextToHeader(Map requestHeaders, Map transientHeaders) { + if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { + SpanHolder spanHolder = (SpanHolder) transientHeaders.get(CURRENT_SPAN); + Span currentSpan = spanHolder.getSpan(); + OSSpan osSpan = getLastValidSpanInChain(currentSpan); + OTelResourceProvider.getContextPropagators().getTextMapPropagator().inject(context(osSpan), requestHeaders, TEXT_MAP_SETTER); + } + } + + /** + * Fetches the tracing context from headers + */ + public static Context extractTracerContextFromHeader(Map headers) { + return OTelResourceProvider.getContextPropagators().getTextMapPropagator().extract(Context.current(), headers, TEXT_MAP_GETTER); + } + + private static Context context(OSSpan osSpan) { + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(osSpan.getSpanContext())); + } + + private static OSSpan getLastValidSpanInChain(Span span) { + while (span instanceof NoopSpan) { + span = span.getParentSpan(); + } + return (OSSpan) span; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/package-info.java b/server/src/main/java/org/opensearch/tracing/package-info.java new file mode 100644 index 0000000000000..40572895df90c --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * This package contains classes needed for tracing requests. + */ +package org.opensearch.tracing; diff --git a/server/src/main/resources/org/opensearch/bootstrap/security.policy b/server/src/main/resources/org/opensearch/bootstrap/security.policy index 3671782b9d12f..f6ba29763f5f7 100644 --- a/server/src/main/resources/org/opensearch/bootstrap/security.policy +++ b/server/src/main/resources/org/opensearch/bootstrap/security.policy @@ -181,5 +181,8 @@ grant { permission java.io.FilePermission "/sys/fs/cgroup/cpuacct/-", "read"; permission java.io.FilePermission "/sys/fs/cgroup/memory", "read"; permission java.io.FilePermission "/sys/fs/cgroup/memory/-", "read"; + // needed by Opentelemetry + permission java.net.NetPermission "getProxySelector"; + permission java.net.SocketPermission "127.0.0.1:4317", "connect,resolve"; }; diff --git a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java new file mode 100644 index 0000000000000..85f060b4a0acd --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java @@ -0,0 +1,130 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.Tracer; +import org.junit.After; +import org.junit.Before; +import org.mockito.ArgumentCaptor; +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Settings; +import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.threadpool.TestThreadPool; +import org.opensearch.threadpool.ThreadPool; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; + +public class DefaultTracerTests extends OpenSearchTestCase { + + private ThreadPool threadPool; + + private OpenTelemetry openTelemetry; + + private TracerSettings tracerSettings; + + private ArgumentCaptor captor; + + private SpanBuilder mockSpanBuilder; + + private io.opentelemetry.api.trace.Span mockOtelSpan; + + @Before + public void setUp() throws Exception { + super.setUp(); + setupMock(); + threadPool = new TestThreadPool("test"); + } + + @After + public void tearDown() throws Exception { + terminate(threadPool); + super.tearDown(); + } + + public void testStartAndEndSpans() { + DefaultTracer tracer = new DefaultTracer(mock(OpenTelemetry.class), threadPool, mock(TracerSettings.class)); + + tracer.startSpan("foo", Level.INFO); + assertEquals("foo", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("RootSpan", tracer.getCurrentSpan().getSpanName()); + } + + public void testStartSpanAndEndWithNoopSpans() { + DefaultTracer tracer = spy(new DefaultTracer(openTelemetry, threadPool, tracerSettings)); + + tracer.startSpan("span1", Level.ROOT); + tracer.startSpan("span2", Level.TERSE); + tracer.startSpan("span3", Level.INFO); + tracer.startSpan("noop-span-1", Level.DEBUG); + tracer.startSpan("noop-span-2", Level.TRACE); + tracer.startSpan("span4", Level.INFO); + + verify(tracer, times(4)).createOtelSpan(any(), captor.capture()); + verify(mockSpanBuilder, times(4)).startSpan(); + assertEquals("span4", tracer.getCurrentSpan().getSpanName()); + OSSpan value = captor.getValue(); + assertEquals("span3", value.getSpanName()); + tracer.endSpan(); + assertEquals("noop-span-2", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("noop-span-1", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("span3", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("span2", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("span1", tracer.getCurrentSpan().getSpanName()); + tracer.endSpan(); + assertEquals("RootSpan", tracer.getCurrentSpan().getSpanName()); + verify(mockOtelSpan, times(4)).end(); + } + + public void testAddEvent() { + ArgumentCaptor stringCaptorValues = ArgumentCaptor.forClass(String.class); + + DefaultTracer tracer = new DefaultTracer(openTelemetry, threadPool, tracerSettings); + + tracer.startSpan("foo", Level.INFO); + tracer.addEvent("fooEvent"); + tracer.endSpan(); + + tracer.startSpan("bar", Level.DEBUG); + tracer.addEvent("fooEvent"); + tracer.endSpan(); + + verify(mockOtelSpan, times(1)).addEvent(stringCaptorValues.capture()); + assertEquals("fooEvent", stringCaptorValues.getValue()); + } + + private void setupMock() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + tracerSettings = new TracerSettings(settings, clusterSettings); + openTelemetry = mock(OpenTelemetry.class); + Tracer mockTracer = mock(Tracer.class); + when(openTelemetry.getTracer(any(String.class))).thenReturn(mockTracer); + captor = ArgumentCaptor.forClass(OSSpan.class); + mockSpanBuilder = mock(SpanBuilder.class); + mockOtelSpan = mock(io.opentelemetry.api.trace.Span.class); + when(mockOtelSpan.getSpanContext()).thenReturn(mock(SpanContext.class)); + when(mockSpanBuilder.startSpan()).thenReturn(mockOtelSpan); + when(mockSpanBuilder.setParent(any())).thenReturn(mockSpanBuilder); + when(mockTracer.spanBuilder(any(String.class))).thenReturn(mockSpanBuilder); + } + +} diff --git a/server/src/test/java/org/opensearch/tracing/LevelTests.java b/server/src/test/java/org/opensearch/tracing/LevelTests.java new file mode 100644 index 0000000000000..de13d23e85b9c --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/LevelTests.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.test.OpenSearchTestCase; + +public class LevelTests extends OpenSearchTestCase { + + public void testFromStringWithValidStrings() { + for (Level level : Level.values()) { + assertEquals(level, Level.fromString(level.name())); + } + } + + public void testFromStringWithInValidString() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> Level.fromString("randomString")); + assertEquals( + "invalid value for tracing level [randomString], must be in [DISABLED, ROOT, TERSE, INFO, DEBUG, TRACE]", + exception.getMessage() + ); + } +} diff --git a/server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java new file mode 100644 index 0000000000000..cedc722b4d56d --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java @@ -0,0 +1,61 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.junit.After; +import org.junit.Before; +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Settings; +import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.threadpool.ThreadPool; + +import static org.mockito.Mockito.mock; + +public class TracerFactoryTests extends OpenSearchTestCase { + + @Before + public void setup() { + TracerFactory.clear(); + } + + @After + public void close() { + TracerFactory.closeTracer(); + } + + public void testGetTracerWithUninitializedTracerFactory() { + Tracer tracer = TracerFactory.getTracer(); + assertTrue(tracer instanceof NoopTracer); + } + + public void testGetTracerWithTracingDisabledReturnsNoopTracer() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); + TracerSettings tracerSettings = new TracerSettings( + settings, + new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) + ); + TracerFactory.initTracerFactory(mock(ThreadPool.class), tracerSettings); + + Tracer tracer = TracerFactory.getTracer(); + assertTrue(tracer instanceof NoopTracer); + } + + public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + TracerSettings tracerSettings = new TracerSettings( + settings, + new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) + ); + TracerFactory.initTracerFactory(mock(ThreadPool.class), tracerSettings); + + Tracer tracer = TracerFactory.getTracer(); + assertTrue(tracer instanceof DefaultTracer); + + } +} diff --git a/server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java new file mode 100644 index 0000000000000..ed9f494a37cc5 --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java @@ -0,0 +1,60 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.TraceFlags; +import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.context.Context; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; + +public class TracerUtilsTests extends OpenSearchTestCase { + + private static final String TRACE_ID = "4aa59968f31dcbff7807741afa9d7d62"; + private static final String SPAN_ID = "bea205cd25756b5e"; + + public void testAddTracerContextToHeader() { + Span mockSpan = mock(Span.class); + when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); + OSSpan span = new OSSpan("spanName", mockSpan, null, Level.INFO); + SpanHolder spanHolder = new SpanHolder(span); + Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); + Map requestHeaders = new HashMap<>(); + TracerUtils.addTracerContextToHeader(requestHeaders, transientHeaders); + assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); + } + + public void testAddTracerContextToHeaderWithNoopSpan() { + Span mockSpan = mock(Span.class); + when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); + OSSpan span = new OSSpan("spanName", mockSpan, null, Level.INFO); + NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); + SpanHolder spanHolder = new SpanHolder(noopSpan); + Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); + Map requestHeaders = new HashMap<>(); + TracerUtils.addTracerContextToHeader(requestHeaders, transientHeaders); + assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); + } + + public void testExtractTracerContextFromHeader() { + Map requestHeaders = new HashMap<>(); + requestHeaders.put("traceparent", "00-" + TRACE_ID + "-" + SPAN_ID + "-00"); + Context context = TracerUtils.extractTracerContextFromHeader(requestHeaders); + assertEquals(TRACE_ID, Span.fromContext(context).getSpanContext().getTraceId()); + assertEquals(SPAN_ID, Span.fromContext(context).getSpanContext().getSpanId()); + } +} From f275db8c827dc7924bceffcc5f00f036894e0d7a Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 29 May 2023 00:30:54 +0530 Subject: [PATCH 02/38] Extract Otel dependencies to a separate module Signed-off-by: suranjay --- CHANGELOG.md | 2 + buildSrc/version.properties | 3 + distribution/src/config/log4j2.properties | 19 ++ modules/tracer-otel/build.gradle | 69 ++++++ .../opentelemetry-api-1.23.1.jar.sha1 | 0 .../licenses/opentelemetry-api-LICENSE.txt | 0 .../licenses/opentelemetry-api-NOTICE.txt | 0 ...entelemetry-api-logs-1.23.1-alpha.jar.sha1 | 0 .../opentelemetry-api-logs-LICENSE.txt | 0 .../opentelemetry-api-logs-NOTICE.txt | 0 .../opentelemetry-context-1.23.1.jar.sha1 | 0 .../opentelemetry-context-LICENSE.txt | 0 .../licenses/opentelemetry-context-NOTICE.txt | 0 .../opentelemetry-sdk-1.23.1.jar.sha1 | 0 .../licenses/opentelemetry-sdk-LICENSE.txt | 0 .../licenses/opentelemetry-sdk-NOTICE.txt | 0 .../opentelemetry-sdk-common-1.23.1.jar.sha1 | 0 .../opentelemetry-sdk-common-LICENSE.txt | 0 .../opentelemetry-sdk-common-NOTICE.txt | 0 ...entelemetry-sdk-logs-1.23.1-alpha.jar.sha1 | 0 .../opentelemetry-sdk-logs-LICENSE.txt | 0 .../opentelemetry-sdk-logs-NOTICE.txt | 0 .../opentelemetry-sdk-metrics-1.23.1.jar.sha1 | 0 .../opentelemetry-sdk-metrics-LICENSE.txt | 0 .../opentelemetry-sdk-metrics-NOTICE.txt | 0 .../opentelemetry-sdk-trace-1.23.1.jar.sha1 | 0 .../opentelemetry-sdk-trace-LICENSE.txt | 0 .../opentelemetry-sdk-trace-NOTICE.txt | 0 ...pentelemetry-semconv-1.23.1-alpha.jar.sha1 | 0 .../opentelemetry-semconv-LICENSE.txt | 0 .../licenses/opentelemetry-semconv-NOTICE.txt | 0 .../org/opensearch/tracing/DefaultSpan.java | 6 +- .../org/opensearch/tracing/DefaultTracer.java | 81 +++---- .../tracing/OTelResourceProvider.java | 7 +- .../tracing/OTelTracerModulePlugin.java | 55 +++++ .../tracing/OtelTracerHeaderInjector.java | 27 +++ .../org/opensearch/tracing/TracerUtils.java | 35 +-- .../tracing/exporter/FileSpanExporter.java | 81 +++++++ .../org/opensearch/tracing/package-info.java | 12 ++ .../plugin-metadata/plugin-security.policy | 36 ++++ .../tracing/DefaultTracerTests.java | 6 +- .../opensearch/tracing/TracerUtilsTests.java | 11 +- .../exporter/FileSpanExporterTests.java | 94 ++++++++ .../tracing/exporter/MockAppender.java | 61 ++++++ server/build.gradle | 76 ------- server/licenses/kotlin-stdlib-1.6.20.jar.sha1 | 1 - server/licenses/kotlin-stdlib-LICENSE.txt | 202 ------------------ server/licenses/kotlin-stdlib-NOTICE.txt | 0 server/licenses/okhttp-4.10.0.jar.sha1 | 1 - server/licenses/okhttp-LICENSE.txt | 202 ------------------ server/licenses/okhttp-NOTICE.txt | 0 server/licenses/okio-jvm-3.0.0.jar.sha1 | 1 - server/licenses/okio-jvm-LICENSE.txt | 202 ------------------ server/licenses/okio-jvm-NOTICE.txt | 202 ------------------ ...ntelemetry-exporter-common-1.23.1.jar.sha1 | 1 - .../opentelemetry-exporter-common-LICENSE.txt | 202 ------------------ .../opentelemetry-exporter-common-NOTICE.txt | 0 ...pentelemetry-exporter-otlp-1.23.1.jar.sha1 | 1 - .../opentelemetry-exporter-otlp-LICENSE.txt | 202 ------------------ .../opentelemetry-exporter-otlp-NOTICE.txt | 0 ...metry-exporter-otlp-common-1.23.1.jar.sha1 | 1 - ...telemetry-exporter-otlp-common-LICENSE.txt | 202 ------------------ ...ntelemetry-exporter-otlp-common-NOTICE.txt | 0 .../common/settings/ClusterSettings.java | 6 +- .../common/util/concurrent/ThreadContext.java | 6 +- .../main/java/org/opensearch/node/Node.java | 12 +- .../org/opensearch/plugins/TracerPlugin.java | 27 +++ .../java/org/opensearch/tracing/Tracer.java | 2 + .../tracing/TracerHeaderInjector.java | 21 ++ ...{TracerFactory.java => TracerManager.java} | 56 +++-- .../org/opensearch/tracing/TracerModule.java | 97 +++++++++ .../opensearch/tracing/TracerSettings.java | 1 + .../tracing/{ => noop}/NoopSpan.java | 10 +- .../tracing/{ => noop}/NoopTracer.java | 12 +- .../noop/NoopTracerHeaderInjector.java | 29 +++ .../opensearch/tracing/noop/package-info.java | 12 ++ .../org/opensearch/bootstrap/security.policy | 3 - ...toryTests.java => TracerManagerTests.java} | 20 +- 78 files changed, 805 insertions(+), 1610 deletions(-) create mode 100644 modules/tracer-otel/build.gradle rename {server => modules/tracer-otel}/licenses/opentelemetry-api-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-api-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-api-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-api-logs-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-api-logs-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-context-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-context-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-context-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-common-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-common-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-logs-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-logs-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-metrics-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-metrics-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-trace-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-sdk-trace-NOTICE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-semconv-LICENSE.txt (100%) rename {server => modules/tracer-otel}/licenses/opentelemetry-semconv-NOTICE.txt (100%) rename server/src/main/java/org/opensearch/tracing/OSSpan.java => modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java (79%) rename {server => modules/tracer-otel}/src/main/java/org/opensearch/tracing/DefaultTracer.java (72%) rename {server => modules/tracer-otel}/src/main/java/org/opensearch/tracing/OTelResourceProvider.java (85%) create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java rename {server => modules/tracer-otel}/src/main/java/org/opensearch/tracing/TracerUtils.java (61%) create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java create mode 100644 modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy rename {server => modules/tracer-otel}/src/test/java/org/opensearch/tracing/DefaultTracerTests.java (96%) rename {server => modules/tracer-otel}/src/test/java/org/opensearch/tracing/TracerUtilsTests.java (84%) create mode 100644 modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java create mode 100644 modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java delete mode 100644 server/licenses/kotlin-stdlib-1.6.20.jar.sha1 delete mode 100644 server/licenses/kotlin-stdlib-LICENSE.txt delete mode 100644 server/licenses/kotlin-stdlib-NOTICE.txt delete mode 100644 server/licenses/okhttp-4.10.0.jar.sha1 delete mode 100644 server/licenses/okhttp-LICENSE.txt delete mode 100644 server/licenses/okhttp-NOTICE.txt delete mode 100644 server/licenses/okio-jvm-3.0.0.jar.sha1 delete mode 100644 server/licenses/okio-jvm-LICENSE.txt delete mode 100644 server/licenses/okio-jvm-NOTICE.txt delete mode 100644 server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 delete mode 100644 server/licenses/opentelemetry-exporter-common-LICENSE.txt delete mode 100644 server/licenses/opentelemetry-exporter-common-NOTICE.txt delete mode 100644 server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 delete mode 100644 server/licenses/opentelemetry-exporter-otlp-LICENSE.txt delete mode 100644 server/licenses/opentelemetry-exporter-otlp-NOTICE.txt delete mode 100644 server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 delete mode 100644 server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt delete mode 100644 server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt create mode 100644 server/src/main/java/org/opensearch/plugins/TracerPlugin.java create mode 100644 server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java rename server/src/main/java/org/opensearch/tracing/{TracerFactory.java => TracerManager.java} (53%) create mode 100644 server/src/main/java/org/opensearch/tracing/TracerModule.java rename server/src/main/java/org/opensearch/tracing/{ => noop}/NoopSpan.java (76%) rename server/src/main/java/org/opensearch/tracing/{ => noop}/NoopTracer.java (81%) create mode 100644 server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java create mode 100644 server/src/main/java/org/opensearch/tracing/noop/package-info.java rename server/src/test/java/org/opensearch/tracing/{TracerFactoryTests.java => TracerManagerTests.java} (73%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5511b69ca519..34dfa498ee02f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Bump `com.netflix.nebula:nebula-publishing-plugin` from 19.2.0 to 20.3.0 - Bump `com.diffplug.spotless` from 6.17.0 to 6.18.0 - Bump `io.opencensus:opencensus-api` from 0.18.0 to 0.31.1 ([#7291](https://github.com/opensearch-project/OpenSearch/pull/7291)) +- Add Opentelemetry dependencies ([#7543](https://github.com/opensearch-project/OpenSearch/issues/7543)) ### Changed - [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948)) @@ -100,6 +101,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Added @dbwiddis as on OpenSearch maintainer ([#7665](https://github.com/opensearch-project/OpenSearch/pull/7665)) - [Extensions] Add ExtensionAwarePlugin extension point to add custom settings for extensions ([#7526](https://github.com/opensearch-project/OpenSearch/pull/7526)) - Add new cluster setting to set default index replication type ([#7420](https://github.com/opensearch-project/OpenSearch/pull/7420)) +- Add distributed tracing framework ([#7543](https://github.com/opensearch-project/OpenSearch/issues/7543)) ### Dependencies - Bump `com.netflix.nebula:gradle-info-plugin` from 12.0.0 to 12.1.3 (#7564) diff --git a/buildSrc/version.properties b/buildSrc/version.properties index 549f2574581d3..2859cea764807 100644 --- a/buildSrc/version.properties +++ b/buildSrc/version.properties @@ -57,3 +57,6 @@ bytebuddy = 1.14.3 # benchmark dependencies jmh = 1.35 + +# opentelemetry dependencies +opentelemetry = 1.23.1 diff --git a/distribution/src/config/log4j2.properties b/distribution/src/config/log4j2.properties index bb27aaf2e22e6..7017ef854c96d 100644 --- a/distribution/src/config/log4j2.properties +++ b/distribution/src/config/log4j2.properties @@ -232,3 +232,22 @@ logger.task_detailslog_rolling.level = trace logger.task_detailslog_rolling.appenderRef.task_detailslog_rolling.ref = task_detailslog_rolling logger.task_detailslog_rolling.appenderRef.task_detailslog_rolling_old.ref = task_detailslog_rolling_old logger.task_detailslog_rolling.additivity = false +######## Distributed Tracing logs JSON #################### +appender.tracing_log_rolling.type = RollingFile +appender.tracing_log_rolling.name = tracing_log_rolling +appender.tracing_log_rolling.fileName = ${sys:opensearch.logs.base_path}${sys:file.separator}${sys:opensearch.logs.cluster_name}_tracing.trace +appender.tracing_log_rolling.filePermissions = rw-r----- +appender.tracing_log_rolling.layout.type = PatternLayout +appender.tracing_log_rolling.layout.pattern = %m%n +appender.tracing_log_rolling.filePattern = ${sys:opensearch.logs.base_path}${sys:file.separator}${sys:opensearch.logs.cluster_name}_tracing-%i.trace.gz +appender.tracing_log_rolling.policies.type = Policies +appender.tracing_log_rolling.policies.size.type = SizeBasedTriggeringPolicy +appender.tracing_log_rolling.policies.size.size = 1GB +appender.tracing_log_rolling.strategy.type = DefaultRolloverStrategy +appender.tracing_log_rolling.strategy.max = 4 +################################################# +logger.tracing_log.name = tracing_log +logger.tracing_log.level = trace +logger.tracing_log.appenderRef.tracing_log_rolling.ref = tracing_log_rolling +logger.tracing_log.appenderRef.tracing_log_rolling_old.ref = tracing_log_rolling +logger.tracing_log.additivity = false diff --git a/modules/tracer-otel/build.gradle b/modules/tracer-otel/build.gradle new file mode 100644 index 0000000000000..5413d4a4d3990 --- /dev/null +++ b/modules/tracer-otel/build.gradle @@ -0,0 +1,69 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.tools.ant.taskdefs.condition.Os +import org.opensearch.gradle.Architecture +import org.opensearch.gradle.OS +import org.opensearch.gradle.info.BuildParams + +opensearchplugin { + description 'Opentelemetry based Tracer implementation.' + classname 'org.opensearch.tracing.OTelTracerModulePlugin' + hasClientJar = true +} + +dependencies { + api "io.opentelemetry:opentelemetry-api:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-context:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-sdk-common:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-sdk-trace:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-sdk-metrics:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-semconv:${versions.opentelemetry}-alpha" + api "io.opentelemetry:opentelemetry-sdk-logs:${versions.opentelemetry}-alpha" + api "io.opentelemetry:opentelemetry-api-logs:${versions.opentelemetry}-alpha" +} + + +thirdPartyAudit { + ignoreViolations( + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField', + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerIndexField', + 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerLimitField', + 'io.opentelemetry.internal.shaded.jctools.util.UnsafeAccess', + 'io.opentelemetry.internal.shaded.jctools.util.UnsafeRefArrayAccess' + ) + + ignoreMissingClasses( + 'io.opentelemetry.api.events.EventEmitter', + 'io.opentelemetry.api.events.EventEmitterBuilder', + 'io.opentelemetry.api.events.EventEmitterProvider' + ) +} diff --git a/server/licenses/opentelemetry-api-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-api-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-api-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-api-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-api-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-api-LICENSE.txt diff --git a/server/licenses/opentelemetry-api-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-api-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-api-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-api-NOTICE.txt diff --git a/server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 diff --git a/server/licenses/opentelemetry-api-logs-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-api-logs-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-api-logs-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-api-logs-LICENSE.txt diff --git a/server/licenses/opentelemetry-api-logs-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-api-logs-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-api-logs-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-api-logs-NOTICE.txt diff --git a/server/licenses/opentelemetry-context-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-context-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-context-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-context-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-context-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-context-LICENSE.txt diff --git a/server/licenses/opentelemetry-context-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-context-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-context-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-context-NOTICE.txt diff --git a/server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-sdk-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-sdk-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-LICENSE.txt diff --git a/server/licenses/opentelemetry-sdk-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-NOTICE.txt diff --git a/server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-sdk-common-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-common-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-common-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-common-LICENSE.txt diff --git a/server/licenses/opentelemetry-sdk-common-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-common-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-common-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-common-NOTICE.txt diff --git a/server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 diff --git a/server/licenses/opentelemetry-sdk-logs-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-logs-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt diff --git a/server/licenses/opentelemetry-sdk-logs-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-logs-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt diff --git a/server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-sdk-metrics-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-metrics-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt diff --git a/server/licenses/opentelemetry-sdk-metrics-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-metrics-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt diff --git a/server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 diff --git a/server/licenses/opentelemetry-sdk-trace-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-trace-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt diff --git a/server/licenses/opentelemetry-sdk-trace-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-sdk-trace-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt diff --git a/server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 similarity index 100% rename from server/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 rename to modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 diff --git a/server/licenses/opentelemetry-semconv-LICENSE.txt b/modules/tracer-otel/licenses/opentelemetry-semconv-LICENSE.txt similarity index 100% rename from server/licenses/opentelemetry-semconv-LICENSE.txt rename to modules/tracer-otel/licenses/opentelemetry-semconv-LICENSE.txt diff --git a/server/licenses/opentelemetry-semconv-NOTICE.txt b/modules/tracer-otel/licenses/opentelemetry-semconv-NOTICE.txt similarity index 100% rename from server/licenses/opentelemetry-semconv-NOTICE.txt rename to modules/tracer-otel/licenses/opentelemetry-semconv-NOTICE.txt diff --git a/server/src/main/java/org/opensearch/tracing/OSSpan.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java similarity index 79% rename from server/src/main/java/org/opensearch/tracing/OSSpan.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java index d5b60799cef0c..77744c4101ae7 100644 --- a/server/src/main/java/org/opensearch/tracing/OSSpan.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java @@ -11,17 +11,17 @@ import io.opentelemetry.api.trace.SpanContext; /** - * Default implementation of {@link Span}. It keeps a reference of OpenTelemetry Span and handles span + * Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span * lifecycle management by delegating calls to it. */ -class OSSpan implements Span { +class DefaultSpan implements Span { private final String spanName; private final io.opentelemetry.api.trace.Span otelSpan; private final Span parentSpan; private final Level level; - public OSSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { + public DefaultSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { this.spanName = spanName; this.otelSpan = span; this.parentSpan = parentSpan; diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java similarity index 72% rename from server/src/main/java/org/opensearch/tracing/DefaultTracer.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java index ecaab906a5760..c4a06bc5f73bf 100644 --- a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java @@ -15,6 +15,7 @@ import org.apache.logging.log4j.Logger; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.threadpool.ThreadPool; +import org.opensearch.tracing.noop.NoopSpan; import java.io.Closeable; import java.io.IOException; @@ -30,8 +31,6 @@ */ public class DefaultTracer implements Tracer { - public static final String CURRENT_SPAN = "current_span"; - private static final Logger logger = LogManager.getLogger(DefaultTracer.class); private static final String TRACE_ID = "trace_id"; private static final String SPAN_ID = "span_id"; @@ -46,6 +45,13 @@ public class DefaultTracer implements Tracer { private final io.opentelemetry.api.trace.Tracer otelTracer; private final OpenTelemetry openTelemetry; + /** + * Creates DefaultTracer instance + * + * @param openTelemetry Otel global Opentelemetry instance + * @param threadPool Thread pool + * @param tracerSettings tracer related settings + */ public DefaultTracer(OpenTelemetry openTelemetry, ThreadPool threadPool, TracerSettings tracerSettings) { this.openTelemetry = openTelemetry; this.otelTracer = openTelemetry.getTracer("os-tracer"); @@ -93,8 +99,8 @@ public void addAttribute(String key, boolean value) { @Override public void addEvent(String event) { Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof OSSpan && ((OSSpan) currentSpan).getOtelSpan() != null) { - ((OSSpan) currentSpan).getOtelSpan().addEvent(event); + if (currentSpan instanceof DefaultSpan && ((DefaultSpan) currentSpan).getOtelSpan() != null) { + ((DefaultSpan) currentSpan).getOtelSpan().addEvent(event); } } @@ -119,7 +125,7 @@ private Span spanFromHeader() { Context context = TracerUtils.extractTracerContextFromHeader(threadPool.getThreadContext().getHeaders()); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OSSpan(ROOT_SPAN, span, null, Level.ROOT); + return new DefaultSpan(ROOT_SPAN, span, null, Level.ROOT); } return null; } @@ -132,14 +138,14 @@ private Optional spanFromThreadContext() { } private Span createSpan(String spanName, Span parentSpan, Level level) { - return isLevelEnabled(level) ? createOSSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); + return isLevelEnabled(level) ? createDefaultSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); } - private Span createOSSpan(String spanName, Span parentSpan, Level level) { - OSSpan parentOSSpan = getLastValidSpanInChain(parentSpan); - io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentOSSpan); - Span span = new OSSpan(spanName, otelSpan, parentSpan, level); - logger.debug( + private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { + DefaultSpan parentDefaultSpan = getLastValidSpanInChain(parentSpan); + io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentDefaultSpan); + Span span = new DefaultSpan(spanName, otelSpan, parentSpan, level); + logger.trace( "Starting OtelSpan spanId:{} name:{}: traceId:{}", otelSpan.getSpanContext().getSpanId(), span.getSpanName(), @@ -149,22 +155,22 @@ private Span createOSSpan(String spanName, Span parentSpan, Level level) { } private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { - logger.debug("Starting Noop span name:{}", spanName); + logger.trace("Starting Noop span name:{}", spanName); return new NoopSpan(spanName, parentSpan, level); } - private OSSpan getLastValidSpanInChain(Span parentSpan) { + private DefaultSpan getLastValidSpanInChain(Span parentSpan) { while (parentSpan instanceof NoopSpan) { parentSpan = parentSpan.getParentSpan(); } - return (OSSpan) parentSpan; + return (DefaultSpan) parentSpan; } // visible for testing - io.opentelemetry.api.trace.Span createOtelSpan(String spanName, OSSpan parentOSSpan) { - return parentOSSpan == null + io.opentelemetry.api.trace.Span createOtelSpan(String spanName, DefaultSpan parentDefaultSpan) { + return parentDefaultSpan == null ? otelTracer.spanBuilder(spanName).startSpan() - : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentOSSpan.getOtelSpan())).startSpan(); + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentDefaultSpan.getOtelSpan())).startSpan(); } private boolean isLevelEnabled(Level level) { @@ -186,42 +192,45 @@ private void setCurrentSpanInContext(Span span) { } private void endSpan(Span span) { - if (span instanceof OSSpan && ((OSSpan) span).getOtelSpan() != null) { - OSSpan osSpan = (OSSpan) span; - logger.debug( + if (span instanceof DefaultSpan && ((DefaultSpan) span).getOtelSpan() != null) { + DefaultSpan defaultSpan = (DefaultSpan) span; + logger.trace( "Ending span spanId:{} name:{}: traceId:{}", - osSpan.getSpanContext().getSpanId(), + defaultSpan.getSpanContext().getSpanId(), span.getSpanName(), - osSpan.getSpanContext().getTraceId() + defaultSpan.getSpanContext().getTraceId() ); - osSpan.getOtelSpan().end(); + defaultSpan.getOtelSpan().end(); } else { - logger.debug("Ending noop span name:{}", span.getSpanName()); + logger.trace("Ending noop span name:{}", span.getSpanName()); } } private void setSpanAttributes(Span span) { - if (span instanceof OSSpan) { - addDefaultAttributes((OSSpan) span); + if (span instanceof DefaultSpan) { + addDefaultAttributes((DefaultSpan) span); } } private void addSingleAttribute(AttributeKey key, T value) { Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof OSSpan && ((OSSpan) currentSpan).getOtelSpan() != null) { - ((OSSpan) currentSpan).getOtelSpan().setAttribute(key, value); + if (currentSpan instanceof DefaultSpan && ((DefaultSpan) currentSpan).getOtelSpan() != null) { + ((DefaultSpan) currentSpan).getOtelSpan().setAttribute(key, value); } } - private void addDefaultAttributes(OSSpan osSpan) { - if (osSpan != null) { - addSingleAttribute(AttributeKey.stringKey(SPAN_ID), osSpan.getSpanContext().getSpanId()); - addSingleAttribute(AttributeKey.stringKey(TRACE_ID), osSpan.getSpanContext().getTraceId()); - addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), osSpan.getSpanName()); + private void addDefaultAttributes(DefaultSpan defaultSpan) { + if (defaultSpan != null) { + addSingleAttribute(AttributeKey.stringKey(SPAN_ID), defaultSpan.getSpanContext().getSpanId()); + addSingleAttribute(AttributeKey.stringKey(TRACE_ID), defaultSpan.getSpanContext().getTraceId()); + addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), defaultSpan.getSpanName()); addSingleAttribute(AttributeKey.stringKey(THREAD_NAME), Thread.currentThread().getName()); - if (osSpan.getParentSpan() != null && osSpan.getParentSpan() instanceof OSSpan) { - addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_ID), ((OSSpan) osSpan.getParentSpan()).getSpanContext().getSpanId()); - addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), osSpan.getParentSpan().getSpanName()); + if (defaultSpan.getParentSpan() != null && defaultSpan.getParentSpan() instanceof DefaultSpan) { + addSingleAttribute( + AttributeKey.stringKey(PARENT_SPAN_ID), + ((DefaultSpan) defaultSpan.getParentSpan()).getSpanContext().getSpanId() + ); + addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), defaultSpan.getParentSpan().getSpanName()); } } } diff --git a/server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java similarity index 85% rename from server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java index 1eaedef88a912..b2bea01cc16df 100644 --- a/server/src/main/java/org/opensearch/tracing/OTelResourceProvider.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java @@ -12,12 +12,12 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import org.opensearch.tracing.exporter.FileSpanExporter; import java.util.concurrent.TimeUnit; @@ -26,20 +26,19 @@ */ class OTelResourceProvider { - private static final Resource resource; private static final ContextPropagators contextPropagators; private static volatile OpenTelemetry OPEN_TELEMETRY; static { - resource = Resource.getDefault().merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch"))); contextPropagators = ContextPropagators.create(W3CTraceContextPropagator.getInstance()); } static OpenTelemetry getOrCreateOpenTelemetryInstance(TracerSettings tracerSettings) { if (OPEN_TELEMETRY == null) { + Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor( - BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().setTimeout(10, TimeUnit.SECONDS).build()) + BatchSpanProcessor.builder(new FileSpanExporter()) .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java new file mode 100644 index 0000000000000..845028cf9c7b9 --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import org.opensearch.common.settings.Settings; +import org.opensearch.plugins.Plugin; +import org.opensearch.plugins.TracerPlugin; +import org.opensearch.threadpool.ThreadPool; + +import java.util.Collections; +import java.util.Map; +import java.util.function.Supplier; + +/** + * Tracer plugin based on Otel + */ +public class OTelTracerModulePlugin extends Plugin implements TracerPlugin { + + private static final String OTEL_TRACER_NAME = "otel"; + + /** + * No-args constructor + */ + public OTelTracerModulePlugin() {} + + @Override + public Settings additionalSettings() { + return Settings.builder() + // set Otel tracer as default tracer + .put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) + .build(); + } + + @Override + public Map> getTracers(ThreadPool threadPool, TracerSettings tracerSettings) { + return Collections.singletonMap(OTEL_TRACER_NAME, () -> createDefaultTracer(threadPool, tracerSettings)); + } + + @Override + public Map getHeaderInjectors() { + return Collections.singletonMap(OTEL_TRACER_NAME, new OtelTracerHeaderInjector()); + } + + private Tracer createDefaultTracer(ThreadPool threadPool, TracerSettings tracerSettings) { + OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); + return new DefaultTracer(openTelemetry, threadPool, tracerSettings); + } +} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java new file mode 100644 index 0000000000000..1b4b2682a11cd --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * Otel based header injector. This adds Otel headers to facilitate context propagation. + */ +public class OtelTracerHeaderInjector implements TracerHeaderInjector { + /** + * No-args constructor + */ + public OtelTracerHeaderInjector() {} + + @Override + public BiConsumer, Map> injectHeader() { + return TracerUtils.addTracerContextToHeader(); + } +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerUtils.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java similarity index 61% rename from server/src/main/java/org/opensearch/tracing/TracerUtils.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java index 3f1234088a1d3..d1eadecba3bed 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerUtils.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java @@ -11,16 +11,22 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapSetter; +import org.opensearch.tracing.noop.NoopSpan; import java.util.Map; +import java.util.function.BiConsumer; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.tracing.Tracer.CURRENT_SPAN; /** * Contains utils methods for tracing */ public class TracerUtils { + private TracerUtils() { + + } + private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { if (carrier != null) { carrier.put(key, value); @@ -45,30 +51,35 @@ public String get(Map headers, String key) { /** * Adds current active span as tracing context in the header during outbound calls */ - public static void addTracerContextToHeader(Map requestHeaders, Map transientHeaders) { - if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { - SpanHolder spanHolder = (SpanHolder) transientHeaders.get(CURRENT_SPAN); - Span currentSpan = spanHolder.getSpan(); - OSSpan osSpan = getLastValidSpanInChain(currentSpan); - OTelResourceProvider.getContextPropagators().getTextMapPropagator().inject(context(osSpan), requestHeaders, TEXT_MAP_SETTER); - } + public static final BiConsumer, Map> addTracerContextToHeader() { + return (requestHeaders, transientHeaders) -> { + if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { + SpanHolder spanHolder = (SpanHolder) transientHeaders.get(CURRENT_SPAN); + Span currentSpan = spanHolder.getSpan(); + DefaultSpan defaultSpan = getLastValidSpanInChain(currentSpan); + OTelResourceProvider.getContextPropagators() + .getTextMapPropagator() + .inject(context(defaultSpan), requestHeaders, TEXT_MAP_SETTER); + } + }; } /** * Fetches the tracing context from headers + * @param headers request header map */ public static Context extractTracerContextFromHeader(Map headers) { return OTelResourceProvider.getContextPropagators().getTextMapPropagator().extract(Context.current(), headers, TEXT_MAP_GETTER); } - private static Context context(OSSpan osSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(osSpan.getSpanContext())); + private static Context context(DefaultSpan defaultSpan) { + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(defaultSpan.getSpanContext())); } - private static OSSpan getLastValidSpanInChain(Span span) { + private static DefaultSpan getLastValidSpanInChain(Span span) { while (span instanceof NoopSpan) { span = span.getParentSpan(); } - return (OSSpan) span; + return (DefaultSpan) span; } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java new file mode 100644 index 0000000000000..220b6601a6469 --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java @@ -0,0 +1,81 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing.exporter; + +import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Writes the span to a log file. This is mostly for testing where you can trace one request and all your spans + * will be written to a file. Tracing log file would be available in the logs directory. + */ +public class FileSpanExporter implements SpanExporter { + public static final String TRACING_LOG_PREFIX = "tracing_log"; + private static final Logger TRACING_LOGGER = LogManager.getLogger(TRACING_LOG_PREFIX); + private final Logger DEFAULT_LOGGER = LogManager.getLogger(FileSpanExporter.class); + private final String FIELD_SEPARATOR = "\t"; + + private final AtomicBoolean isShutdown = new AtomicBoolean(); + + @Override + public CompletableResultCode export(Collection spans) { + if (isShutdown.get()) { + return CompletableResultCode.ofFailure(); + } + StringBuilder sb = new StringBuilder(128); + for (SpanData span : spans) { + sb.setLength(0); + InstrumentationScopeInfo instrumentationScopeInfo = span.getInstrumentationScopeInfo(); + sb.append("'") + .append(span.getName()) + .append("'") + .append(FIELD_SEPARATOR) + .append(span.getTraceId()) + .append(FIELD_SEPARATOR) + .append(span.getSpanId()) + .append(FIELD_SEPARATOR) + .append(span.getParentSpanId()) + .append(FIELD_SEPARATOR) + .append(span.getKind()) + .append(FIELD_SEPARATOR) + .append(span.getStartEpochNanos()) + .append(FIELD_SEPARATOR) + .append(span.getEndEpochNanos()) + .append(FIELD_SEPARATOR) + .append("[tracer:") + .append(instrumentationScopeInfo.getName()) + .append(":") + .append(instrumentationScopeInfo.getVersion() == null ? "" : instrumentationScopeInfo.getVersion()) + .append("]") + .append(FIELD_SEPARATOR) + .append(span.getAttributes()); + TRACING_LOGGER.info(sb.toString()); + } + return CompletableResultCode.ofSuccess(); + } + + @Override + public CompletableResultCode flush() { + return CompletableResultCode.ofSuccess(); + } + + @Override + public CompletableResultCode shutdown() { + if (!isShutdown.compareAndSet(false, true)) { + DEFAULT_LOGGER.info("Duplicate shutdown() calls."); + } + return CompletableResultCode.ofSuccess(); + } +} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java new file mode 100644 index 0000000000000..40572895df90c --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * This package contains classes needed for tracing requests. + */ +package org.opensearch.tracing; diff --git a/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy b/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy new file mode 100644 index 0000000000000..ac07c2a265bd8 --- /dev/null +++ b/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +grant { +}; + + diff --git a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java similarity index 96% rename from server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java rename to modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java index 85f060b4a0acd..71c6ed6388d7c 100644 --- a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java @@ -36,7 +36,7 @@ public class DefaultTracerTests extends OpenSearchTestCase { private TracerSettings tracerSettings; - private ArgumentCaptor captor; + private ArgumentCaptor captor; private SpanBuilder mockSpanBuilder; @@ -77,7 +77,7 @@ public void testStartSpanAndEndWithNoopSpans() { verify(tracer, times(4)).createOtelSpan(any(), captor.capture()); verify(mockSpanBuilder, times(4)).startSpan(); assertEquals("span4", tracer.getCurrentSpan().getSpanName()); - OSSpan value = captor.getValue(); + DefaultSpan value = captor.getValue(); assertEquals("span3", value.getSpanName()); tracer.endSpan(); assertEquals("noop-span-2", tracer.getCurrentSpan().getSpanName()); @@ -118,7 +118,7 @@ private void setupMock() { openTelemetry = mock(OpenTelemetry.class); Tracer mockTracer = mock(Tracer.class); when(openTelemetry.getTracer(any(String.class))).thenReturn(mockTracer); - captor = ArgumentCaptor.forClass(OSSpan.class); + captor = ArgumentCaptor.forClass(DefaultSpan.class); mockSpanBuilder = mock(SpanBuilder.class); mockOtelSpan = mock(io.opentelemetry.api.trace.Span.class); when(mockOtelSpan.getSpanContext()).thenReturn(mock(SpanContext.class)); diff --git a/server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java similarity index 84% rename from server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java rename to modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java index ed9f494a37cc5..c943e7645537d 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerUtilsTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java @@ -14,13 +14,14 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.tracing.noop.NoopSpan; import java.util.HashMap; import java.util.Map; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.tracing.Tracer.CURRENT_SPAN; public class TracerUtilsTests extends OpenSearchTestCase { @@ -30,23 +31,23 @@ public class TracerUtilsTests extends OpenSearchTestCase { public void testAddTracerContextToHeader() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - OSSpan span = new OSSpan("spanName", mockSpan, null, Level.INFO); + DefaultSpan span = new DefaultSpan("spanName", mockSpan, null, Level.INFO); SpanHolder spanHolder = new SpanHolder(span); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - TracerUtils.addTracerContextToHeader(requestHeaders, transientHeaders); + TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } public void testAddTracerContextToHeaderWithNoopSpan() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - OSSpan span = new OSSpan("spanName", mockSpan, null, Level.INFO); + DefaultSpan span = new DefaultSpan("spanName", mockSpan, null, Level.INFO); NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); SpanHolder spanHolder = new SpanHolder(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - TracerUtils.addTracerContextToHeader(requestHeaders, transientHeaders); + TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java new file mode 100644 index 0000000000000..6bac3030bceaa --- /dev/null +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java @@ -0,0 +1,94 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing.exporter; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.internal.AttributesMap; +import io.opentelemetry.sdk.trace.data.SpanData; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.mockito.Mockito; +import org.opensearch.common.logging.Loggers; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.Arrays; +import java.util.Locale; + +public class FileSpanExporterTests extends OpenSearchTestCase { + private static MockAppender appender; + private static Logger testLogger1 = LogManager.getLogger(FileSpanExporter.TRACING_LOG_PREFIX); + + @BeforeClass + public static void init() throws IllegalAccessException { + appender = new MockAppender("trace_appender"); + appender.start(); + Loggers.addAppender(testLogger1, appender); + } + + @AfterClass + public static void cleanup() { + Loggers.removeAppender(testLogger1, appender); + appender.stop(); + } + + private final FileSpanExporter spanExporter = new FileSpanExporter(); + + public void testOutputFormat() { + String name = "TestSpan"; + String traceId = "6b44b6eadda4535388c406d3ba8894d4"; + String spanId = "96a0878e2febe8ba"; + String parentSpanId = "72a0878e2febg8fc"; + SpanData mockedSpanData = Mockito.mock(SpanData.class); + Mockito.when(mockedSpanData.getName()).thenReturn(name); + Mockito.when(mockedSpanData.getTraceId()).thenReturn(traceId); + Mockito.when(mockedSpanData.getSpanId()).thenReturn(spanId); + Mockito.when(mockedSpanData.getParentSpanId()).thenReturn(parentSpanId); + Mockito.when(mockedSpanData.getKind()).thenReturn(SpanKind.INTERNAL); + Mockito.when(mockedSpanData.getInstrumentationScopeInfo()) + .thenReturn(InstrumentationScopeInfo.create("instrumentation-library-name", "1.0.0", null)); + + AttributesMap attributesMap = AttributesMap.create(128, 128); + attributesMap.put(AttributeKey.stringKey("SpanId"), spanId); + + Mockito.when(mockedSpanData.getAttributes()).thenReturn(attributesMap); + + spanExporter.export(Arrays.asList(mockedSpanData)); + String logData = appender.getLastEventAndReset().getMessage().getFormattedMessage(); + assertEquals(getExpectedLogMessage(name, traceId, spanId, parentSpanId, attributesMap), logData); + assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush()); + assertEquals(CompletableResultCode.ofSuccess(), spanExporter.shutdown()); + + spanExporter.export(Arrays.asList(mockedSpanData)); + assertNull(appender.getLastEventAndReset()); + } + + private String getExpectedLogMessage(String name, String traceId, String spanId, String parentSpanId, AttributesMap attributesMap) { + return String.format( + Locale.ROOT, + "'%s'\t%s\t%s\t%s\t%s\t%d\t%d\t[%s:%s:%s]\t%s", + name, + traceId, + spanId, + parentSpanId, + "INTERNAL", + 0, + 0, + "tracer", + "instrumentation-library-name", + "1.0.0", + attributesMap + ); + } + +} diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java new file mode 100644 index 0000000000000..b74d2cc8c0820 --- /dev/null +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java @@ -0,0 +1,61 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +package org.opensearch.tracing.exporter; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.filter.RegexFilter; +import org.apache.logging.log4j.message.ParameterizedMessage; + +public class MockAppender extends AbstractAppender { + public LogEvent lastEvent; + + public MockAppender(final String name) throws IllegalAccessException { + super(name, RegexFilter.createFilter(".*(\n.*)*", new String[0], false, null, null), null); + } + + @Override + public void append(LogEvent event) { + lastEvent = event.toImmutable(); + } + + ParameterizedMessage lastParameterizedMessage() { + return (ParameterizedMessage) lastEvent.getMessage(); + } + + public LogEvent getLastEventAndReset() { + LogEvent toReturn = lastEvent; + lastEvent = null; + return toReturn; + } +} diff --git a/server/build.gradle b/server/build.gradle index eefc174b6a403..62c0002dc1398 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -134,23 +134,6 @@ dependencies { // precentil ranks aggregation api 'org.hdrhistogram:HdrHistogram:2.1.12' - // opentelemetry - api 'io.opentelemetry:opentelemetry-api:1.23.1' - api 'io.opentelemetry:opentelemetry-context:1.23.1' - api 'io.opentelemetry:opentelemetry-sdk:1.23.1' - api 'io.opentelemetry:opentelemetry-sdk-common:1.23.1' - api 'io.opentelemetry:opentelemetry-sdk-metrics:1.23.1' - api 'io.opentelemetry:opentelemetry-sdk-trace:1.23.1' - api 'io.opentelemetry:opentelemetry-exporter-otlp:1.23.1' - api 'io.opentelemetry:opentelemetry-exporter-common:1.23.1' - api 'io.opentelemetry:opentelemetry-exporter-otlp-common:1.23.1' - api 'io.opentelemetry:opentelemetry-semconv:1.23.1-alpha' - api 'com.squareup.okhttp3:okhttp:4.10.0' - api 'org.jetbrains.kotlin:kotlin-stdlib:1.6.20' - api 'com.squareup.okio:okio-jvm:3.0.0' - api 'io.opentelemetry:opentelemetry-sdk-logs:1.23.1-alpha' - api 'io.opentelemetry:opentelemetry-api-logs:1.23.1-alpha' - // lucene spatial api "org.locationtech.spatial4j:spatial4j:${versions.spatial4j}", optional api "org.locationtech.jts:jts-core:${versions.jts}", optional @@ -352,59 +335,6 @@ tasks.named("thirdPartyAudit").configure { 'com.google.common.geometry.S2$Metric', 'com.google.common.geometry.S2LatLng', - // from opentelemetry - 'android.net.http.X509TrustManagerExtensions', - 'android.net.ssl.SSLSockets', - 'android.os.Build$VERSION', - 'android.security.NetworkSecurityPolicy', - 'android.util.Log', - 'com.google.common.io.ByteStreams', - 'com.google.common.util.concurrent.FutureCallback', - 'com.google.common.util.concurrent.Futures', - 'com.google.common.util.concurrent.ListenableFuture', - 'com.google.common.util.concurrent.MoreExecutors', - 'io.grpc.CallOptions', - 'io.grpc.Channel', - 'io.grpc.ClientInterceptor', - 'io.grpc.ClientInterceptors', - 'io.grpc.Codec', - 'io.grpc.Codec$Identity', - 'io.grpc.Drainable', - 'io.grpc.KnownLength', - 'io.grpc.ManagedChannel', - 'io.grpc.ManagedChannelBuilder', - 'io.grpc.Metadata', - 'io.grpc.Metadata$Key', - 'io.grpc.MethodDescriptor', - 'io.grpc.MethodDescriptor$Builder', - 'io.grpc.MethodDescriptor$Marshaller', - 'io.grpc.MethodDescriptor$MethodType', - 'io.grpc.Status', - 'io.grpc.Status$Code', - 'io.grpc.netty.GrpcSslContexts', - 'io.grpc.netty.NettyChannelBuilder', - 'io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts', - 'io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder', - 'io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder', - 'io.grpc.okhttp.OkHttpChannelBuilder', - 'io.grpc.stub.AbstractFutureStub', - 'io.grpc.stub.AbstractStub', - 'io.grpc.stub.ClientCalls', - 'io.grpc.stub.MetadataUtils', - 'io.netty.handler.ssl.SslContextBuilder', - 'io.opentelemetry.api.events.EventEmitter', - 'io.opentelemetry.api.events.EventEmitterBuilder', - 'io.opentelemetry.api.events.EventEmitterProvider', - 'io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties', - 'io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider', - 'io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider', - 'org.bouncycastle.jsse.BCSSLParameters', - 'org.bouncycastle.jsse.BCSSLSocket', - 'org.conscrypt.Conscrypt', - 'org.conscrypt.Conscrypt$Version', - 'org.conscrypt.ConscryptHostnameVerifier', - 'org.openjsse.javax.net.ssl.SSLParameters', - 'org.openjsse.javax.net.ssl.SSLSocket' ) @@ -417,12 +347,6 @@ tasks.named("thirdPartyAudit").configure { 'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor', 'com.google.protobuf.UnsafeUtil$MemoryAccessor', - // from opentelemetry - 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField', - 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerIndexField', - 'io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerLimitField', - 'io.opentelemetry.internal.shaded.jctools.util.UnsafeAccess', - 'io.opentelemetry.internal.shaded.jctools.util.UnsafeRefArrayAccess' ) } diff --git a/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 b/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 deleted file mode 100644 index a26a3b6591dcf..0000000000000 --- a/server/licenses/kotlin-stdlib-1.6.20.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -6cedc143badbb4f1c6b7f5a340b04edff1743208 \ No newline at end of file diff --git a/server/licenses/kotlin-stdlib-LICENSE.txt b/server/licenses/kotlin-stdlib-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/kotlin-stdlib-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/kotlin-stdlib-NOTICE.txt b/server/licenses/kotlin-stdlib-NOTICE.txt deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/server/licenses/okhttp-4.10.0.jar.sha1 b/server/licenses/okhttp-4.10.0.jar.sha1 deleted file mode 100644 index 7cd464ff3effb..0000000000000 --- a/server/licenses/okhttp-4.10.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -cd63657ac15770ed1420647154c9f44645533bef \ No newline at end of file diff --git a/server/licenses/okhttp-LICENSE.txt b/server/licenses/okhttp-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/okhttp-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/okhttp-NOTICE.txt b/server/licenses/okhttp-NOTICE.txt deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/server/licenses/okio-jvm-3.0.0.jar.sha1 b/server/licenses/okio-jvm-3.0.0.jar.sha1 deleted file mode 100644 index b75b63ec015bd..0000000000000 --- a/server/licenses/okio-jvm-3.0.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -0ab5a73fa2ccb4a36b0b5c69fe10b16d0255bcf8 \ No newline at end of file diff --git a/server/licenses/okio-jvm-LICENSE.txt b/server/licenses/okio-jvm-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/okio-jvm-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/okio-jvm-NOTICE.txt b/server/licenses/okio-jvm-NOTICE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/okio-jvm-NOTICE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 deleted file mode 100644 index 3cf6f53767f58..0000000000000 --- a/server/licenses/opentelemetry-exporter-common-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -e1e68d1ce6b4661e3a10f36a4ae5f364b06b27ed \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-common-LICENSE.txt b/server/licenses/opentelemetry-exporter-common-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/opentelemetry-exporter-common-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-common-NOTICE.txt b/server/licenses/opentelemetry-exporter-common-NOTICE.txt deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 deleted file mode 100644 index 2ba5197454396..0000000000000 --- a/server/licenses/opentelemetry-exporter-otlp-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -39b79499dcedd4b662c60eecc2db03b1efbdd368 \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt b/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/opentelemetry-exporter-otlp-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-otlp-NOTICE.txt b/server/licenses/opentelemetry-exporter-otlp-NOTICE.txt deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 b/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 deleted file mode 100644 index 3ab5a1acf2bc6..0000000000000 --- a/server/licenses/opentelemetry-exporter-otlp-common-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -0b131ab306d726260a91ea437e7a65b1e31ef417 \ No newline at end of file diff --git a/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt b/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt deleted file mode 100644 index d645695673349..0000000000000 --- a/server/licenses/opentelemetry-exporter-otlp-common-LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt b/server/licenses/opentelemetry-exporter-otlp-common-NOTICE.txt deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 6db763ff148ce..1be07a7c29675 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -51,7 +51,7 @@ import org.opensearch.tasks.TaskManager; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.tasks.consumer.TopNSearchTasksLogger; -import org.opensearch.tracing.TracerSettings; +import org.opensearch.tracing.TracerModule; import org.opensearch.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; @@ -657,7 +657,9 @@ public void apply(Settings value, Settings current, Settings previous) { TracerSettings.TRACER_LEVEL_SETTING, TracerSettings.TRACER_EXPORTER_DELAY_SETTING, TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, - TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING + TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, + TracerModule.TRACER_DEFAULT_TYPE_SETTING, + TracerModule.TRACER_TYPE_SETTING ) ) ); diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 5e81d130e7a22..029ece235abba 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -45,7 +45,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.http.HttpTransportSettings; import org.opensearch.tracing.SpanHolder; -import org.opensearch.tracing.TracerUtils; +import org.opensearch.tracing.TracerManager; import org.opensearch.tasks.Task; import java.io.IOException; @@ -68,8 +68,8 @@ import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_COUNT; import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_SIZE; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; +import static org.opensearch.tracing.Tracer.CURRENT_SPAN; /** * A ThreadContext is a map of string headers and a transient map of keyed objects that are associated with @@ -725,7 +725,7 @@ private ThreadContextStruct copyHeaders(Iterable> head } private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { - TracerUtils.addTracerContextToHeader(this.requestHeaders, this.transientHeaders); + TracerManager.getTracerHeaderInjector().injectHeader().accept(this.requestHeaders, this.transientHeaders); final Map requestHeaders; if (defaultHeaders.isEmpty()) { diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index fd522b7a14c58..bd50f6521608d 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -56,7 +56,7 @@ import org.opensearch.monitor.fs.FsProbe; import org.opensearch.plugins.ExtensionAwarePlugin; import org.opensearch.plugins.SearchPipelinePlugin; -import org.opensearch.tracing.TracerFactory; +import org.opensearch.tracing.TracerManager; import org.opensearch.search.backpressure.SearchBackpressureService; import org.opensearch.search.backpressure.settings.SearchBackpressureSettings; import org.opensearch.search.pipeline.SearchPipelineService; @@ -64,6 +64,7 @@ import org.opensearch.tasks.consumer.TopNSearchTasksLogger; import org.opensearch.threadpool.RunnableTaskExecutionListener; import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory; +import org.opensearch.tracing.TracerModule; import org.opensearch.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.core.Assertions; @@ -194,6 +195,7 @@ import org.opensearch.plugins.ScriptPlugin; import org.opensearch.plugins.SearchPlugin; import org.opensearch.plugins.SystemIndexPlugin; +import org.opensearch.plugins.TracerPlugin; import org.opensearch.repositories.RepositoriesModule; import org.opensearch.repositories.RepositoriesService; import org.opensearch.rest.RestController; @@ -1011,8 +1013,10 @@ protected Node( ); final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); - TracerFactory.initTracerFactory(threadPool, tracerSettings); - resourcesToClose.add(TracerFactory::closeTracer); + List tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class); + TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings); + TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector()); + resourcesToClose.add(TracerManager::closeTracer); final List> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class) .stream() @@ -1471,7 +1475,7 @@ public synchronized void close() throws IOException { toClose.add(() -> stopWatch.stop().start("node_environment")); toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(stopWatch::stop); - toClose.add(TracerFactory::closeTracer); + toClose.add(TracerManager::closeTracer); if (logger.isTraceEnabled()) { toClose.add(() -> logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint())); diff --git a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java new file mode 100644 index 0000000000000..830a4f6e3a1f1 --- /dev/null +++ b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.plugins; + +import org.opensearch.threadpool.ThreadPool; +import org.opensearch.tracing.Tracer; +import org.opensearch.tracing.TracerHeaderInjector; +import org.opensearch.tracing.TracerSettings; + +import java.util.Map; +import java.util.function.Supplier; + +/** + * Plugin for extending tracing related classes + */ +public interface TracerPlugin { + + Map> getTracers(ThreadPool threadPool, TracerSettings tracerSettings); + + Map getHeaderInjectors(); +} diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/server/src/main/java/org/opensearch/tracing/Tracer.java index 147d45f117654..3c6230681e7db 100644 --- a/server/src/main/java/org/opensearch/tracing/Tracer.java +++ b/server/src/main/java/org/opensearch/tracing/Tracer.java @@ -18,6 +18,8 @@ */ public interface Tracer extends Closeable { + String CURRENT_SPAN = "current_span"; + /** * Starts the {@link Span} with given name and level * diff --git a/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java b/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java new file mode 100644 index 0000000000000..e0780e11ad3ef --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * Interface to add in tracing related context in header + */ +public interface TracerHeaderInjector { + + BiConsumer, Map> injectHeader(); + +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/tracing/TracerManager.java similarity index 53% rename from server/src/main/java/org/opensearch/tracing/TracerFactory.java rename to server/src/main/java/org/opensearch/tracing/TracerManager.java index e36b46abb2a6a..a8726c5112656 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerFactory.java +++ b/server/src/main/java/org/opensearch/tracing/TracerManager.java @@ -8,38 +8,44 @@ package org.opensearch.tracing; -import io.opentelemetry.api.OpenTelemetry; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.threadpool.ThreadPool; +import org.opensearch.tracing.noop.NoopTracer; +import org.opensearch.tracing.noop.NoopTracerHeaderInjector; import java.io.IOException; +import java.util.function.Supplier; /** - * TracerFactory represents a single global class that is used to access tracers. + * TracerManager represents a single global class that is used to access tracers. * - * The Tracer singleton object can be retrieved using TracerFactory.getTracer(). The TracerFactory object + * The Tracer singleton object can be retrieved using TracerManager.getTracer(). The TracerManager object * is created during class initialization and cannot subsequently be changed. */ -public class TracerFactory { +public class TracerManager { - private static final Logger logger = LogManager.getLogger(TracerFactory.class); - private static final Tracer noopTracer = new NoopTracer(); - private static volatile TracerFactory INSTANCE; + private static final Logger logger = LogManager.getLogger(TracerManager.class); + private static volatile TracerManager INSTANCE; - private final ThreadPool threadPool; - private final TracerSettings tracerSettings; - private final Object mutex = new Object(); private volatile Tracer defaultTracer; + private final Object mutex = new Object(); + private final TracerSettings tracerSettings; + private final Supplier tracerSupplier; + private final TracerHeaderInjector tracerHeaderInjector; /** * Initializes the TracerFactory singleton instance - * @param threadPool threadpool instance - * @param tracerSettings tracer settings instance + * + * @param tracerSettings tracer settings instance + * @param tracerHeaderInjector tracer header injector */ - public static synchronized void initTracerFactory(ThreadPool threadPool, TracerSettings tracerSettings) { + public static synchronized void initTracerManager( + TracerSettings tracerSettings, + Supplier tracerSupplier, + TracerHeaderInjector tracerHeaderInjector + ) { if (INSTANCE == null) { - INSTANCE = new TracerFactory(threadPool, tracerSettings); + INSTANCE = new TracerManager(tracerSettings, tracerSupplier, tracerHeaderInjector); } else { logger.warn("Trying to double initialize TracerFactory, skipping"); } @@ -50,7 +56,11 @@ public static synchronized void initTracerFactory(ThreadPool threadPool, TracerS * @return Tracer instance */ public static Tracer getTracer() { - return INSTANCE == null ? noopTracer : INSTANCE.tracer(); + return INSTANCE == null ? NoopTracer.INSTANCE : INSTANCE.tracer(); + } + + public static TracerHeaderInjector getTracerHeaderInjector() { + return INSTANCE == null ? NoopTracerHeaderInjector.INSTANCE : INSTANCE.tracerHeaderInjector(); } /** @@ -66,13 +76,18 @@ public static void closeTracer() { } } - public TracerFactory(ThreadPool threadPool, TracerSettings tracerSettings) { - this.threadPool = threadPool; + public TracerManager(TracerSettings tracerSettings, Supplier tracerSupplier, TracerHeaderInjector tracerHeaderInjector) { this.tracerSettings = tracerSettings; + this.tracerSupplier = tracerSupplier; + this.tracerHeaderInjector = tracerHeaderInjector; } private Tracer tracer() { - return isTracingDisabled() ? noopTracer : getOrCreateDefaultTracerInstance(); + return isTracingDisabled() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); + } + + private TracerHeaderInjector tracerHeaderInjector() { + return isTracingDisabled() ? NoopTracerHeaderInjector.INSTANCE : tracerHeaderInjector; } private boolean isTracingDisabled() { @@ -84,8 +99,7 @@ private Tracer getOrCreateDefaultTracerInstance() { synchronized (mutex) { if (defaultTracer == null) { logger.info("Creating Otel tracer..."); - OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); - defaultTracer = new DefaultTracer(openTelemetry, threadPool, tracerSettings); + defaultTracer = tracerSupplier.get(); } } } diff --git a/server/src/main/java/org/opensearch/tracing/TracerModule.java b/server/src/main/java/org/opensearch/tracing/TracerModule.java new file mode 100644 index 0000000000000..1068820257e73 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/TracerModule.java @@ -0,0 +1,97 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.plugins.TracerPlugin; +import org.opensearch.threadpool.ThreadPool; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +/** + * A module for loading classes for tracer + * + * @opensearch.internal + */ +public class TracerModule { + + private static final String TRACER_TYPE_DEFAULT_KEY = "tracer.type.default"; + private static final String TRACER_TYPE_KEY = "tracer.type"; + + public static final Setting TRACER_DEFAULT_TYPE_SETTING = Setting.simpleString( + TRACER_TYPE_DEFAULT_KEY, + Setting.Property.NodeScope + ); + public static final Setting TRACER_TYPE_SETTING = Setting.simpleString(TRACER_TYPE_KEY, Setting.Property.NodeScope); + + private final Settings settings; + private final Map> tracerFactories = new HashMap<>(); + private final Map tracerHeaderInjectors = new HashMap<>(); + + public TracerModule(Settings settings, List tracerPlugins, ThreadPool threadPool, TracerSettings tracerSettings) { + this.settings = settings; + + for (TracerPlugin tracerPlugin : tracerPlugins) { + Map> tracerFactory = tracerPlugin.getTracers(threadPool, tracerSettings); + for (Map.Entry> entry : tracerFactory.entrySet()) { + registerTracer(entry.getKey(), entry.getValue()); + } + + Map headerInjectors = tracerPlugin.getHeaderInjectors(); + for (Map.Entry entry : headerInjectors.entrySet()) { + registerTracerHeaderInjector(entry.getKey(), entry.getValue()); + } + + } + } + + public Supplier getTracerSupplier() { + final String tracerType = getTracerType(); + + final Supplier factory = tracerFactories.get(tracerType); + /*if (factory == null) { + throw new IllegalStateException("Unsupported tracer.type [" + tracerType + "]"); + }*/ + return factory; + } + + public TracerHeaderInjector getTracerHeaderInjector() { + final String tracerType = getTracerType(); + + final TracerHeaderInjector tracerHeaderInjector = tracerHeaderInjectors.get(tracerType); + /*if (tracerHeaderInjector == null) { + throw new IllegalStateException("Unsupported tracer.type [" + tracerType + "]"); + }*/ + return tracerHeaderInjector; + } + + private String getTracerType() { + final String tracerType = TRACER_DEFAULT_TYPE_SETTING.exists(settings) + ? TRACER_DEFAULT_TYPE_SETTING.get(settings) + : TRACER_TYPE_SETTING.get(settings); + return tracerType; + } + + private void registerTracer(String key, Supplier factory) { + if (tracerFactories.putIfAbsent(key, factory) != null) { + throw new IllegalArgumentException("tracer for name: " + key + " is already registered"); + } + } + + private void registerTracerHeaderInjector(String key, TracerHeaderInjector tracerHeaderInjector) { + if (tracerHeaderInjectors.putIfAbsent(key, tracerHeaderInjector) != null) { + throw new IllegalArgumentException("tracer injector for name: " + key + " is already registered"); + } + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerSettings.java b/server/src/main/java/org/opensearch/tracing/TracerSettings.java index d595217039672..5e0c3954d2d1d 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerSettings.java +++ b/server/src/main/java/org/opensearch/tracing/TracerSettings.java @@ -17,6 +17,7 @@ * Wrapper class to encapsulate tracing related settings */ public class TracerSettings { + // TODO move this public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( "tracer.exporter.batch_size", 512, diff --git a/server/src/main/java/org/opensearch/tracing/NoopSpan.java b/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java similarity index 76% rename from server/src/main/java/org/opensearch/tracing/NoopSpan.java rename to server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java index fb7bc0f433654..516f07380ca15 100644 --- a/server/src/main/java/org/opensearch/tracing/NoopSpan.java +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java @@ -6,17 +6,15 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.tracing.noop; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.opensearch.tracing.Level; +import org.opensearch.tracing.Span; /** * No-op implementation of Span */ -class NoopSpan implements Span { - private static final Logger logger = LogManager.getLogger(NoopSpan.class); - +public class NoopSpan implements Span { private final String spanName; private final Span parentSpan; private final Level level; diff --git a/server/src/main/java/org/opensearch/tracing/NoopTracer.java b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java similarity index 81% rename from server/src/main/java/org/opensearch/tracing/NoopTracer.java rename to server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java index b6f6a90026dba..73f0a7e1a88de 100644 --- a/server/src/main/java/org/opensearch/tracing/NoopTracer.java +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java @@ -6,12 +6,20 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.tracing.noop; + +import org.opensearch.tracing.Level; +import org.opensearch.tracing.Span; +import org.opensearch.tracing.Tracer; /** * No-op implementation of Tracer */ -class NoopTracer implements Tracer { +public class NoopTracer implements Tracer { + + public static final Tracer INSTANCE = new NoopTracer(); + + private NoopTracer() {} @Override public void startSpan(String spanName, Level level) { diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java b/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java new file mode 100644 index 0000000000000..0f4a419e0d38d --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing.noop; + +import org.opensearch.tracing.TracerHeaderInjector; + +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * No-op implementation of TracerHeaderInjector + */ +public class NoopTracerHeaderInjector implements TracerHeaderInjector { + + public static final TracerHeaderInjector INSTANCE = new NoopTracerHeaderInjector(); + + private NoopTracerHeaderInjector() {} + + @Override + public BiConsumer, Map> injectHeader() { + return (x, y) -> {}; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/noop/package-info.java b/server/src/main/java/org/opensearch/tracing/noop/package-info.java new file mode 100644 index 0000000000000..66b557c48ed20 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/noop/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains No-op implementations + */ +package org.opensearch.tracing.noop; diff --git a/server/src/main/resources/org/opensearch/bootstrap/security.policy b/server/src/main/resources/org/opensearch/bootstrap/security.policy index f6ba29763f5f7..3671782b9d12f 100644 --- a/server/src/main/resources/org/opensearch/bootstrap/security.policy +++ b/server/src/main/resources/org/opensearch/bootstrap/security.policy @@ -181,8 +181,5 @@ grant { permission java.io.FilePermission "/sys/fs/cgroup/cpuacct/-", "read"; permission java.io.FilePermission "/sys/fs/cgroup/memory", "read"; permission java.io.FilePermission "/sys/fs/cgroup/memory/-", "read"; - // needed by Opentelemetry - permission java.net.NetPermission "getProxySelector"; - permission java.net.SocketPermission "127.0.0.1:4317", "connect,resolve"; }; diff --git a/server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java similarity index 73% rename from server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java rename to server/src/test/java/org/opensearch/tracing/TracerManagerTests.java index cedc722b4d56d..01e7bb7c0116f 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerFactoryTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java @@ -13,24 +13,24 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.ThreadPool; +import org.opensearch.tracing.noop.NoopTracer; import static org.mockito.Mockito.mock; -public class TracerFactoryTests extends OpenSearchTestCase { +public class TracerManagerTests extends OpenSearchTestCase { @Before public void setup() { - TracerFactory.clear(); + TracerManager.clear(); } @After public void close() { - TracerFactory.closeTracer(); + TracerManager.closeTracer(); } public void testGetTracerWithUninitializedTracerFactory() { - Tracer tracer = TracerFactory.getTracer(); + Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof NoopTracer); } @@ -40,9 +40,9 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) ); - TracerFactory.initTracerFactory(mock(ThreadPool.class), tracerSettings); + TracerManager.initTracerManager(tracerSettings, null, null); - Tracer tracer = TracerFactory.getTracer(); + Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof NoopTracer); } @@ -52,10 +52,10 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) ); - TracerFactory.initTracerFactory(mock(ThreadPool.class), tracerSettings); + TracerManager.initTracerManager(tracerSettings, () -> mock(Tracer.class), null); - Tracer tracer = TracerFactory.getTracer(); - assertTrue(tracer instanceof DefaultTracer); + Tracer tracer = TracerManager.getTracer(); + assertFalse(tracer instanceof NoopTracer); } } From 0d67058f9d79422c51b9a7b610ff070ae3233e27 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 29 May 2023 16:12:41 +0530 Subject: [PATCH 03/38] Fix javadocs error Signed-off-by: suranjay --- .../tracing/exporter/FileSpanExporter.java | 7 ++++++- .../opensearch/tracing/exporter/package-info.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java index 220b6601a6469..511f0ec222c77 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java @@ -22,13 +22,18 @@ * will be written to a file. Tracing log file would be available in the logs directory. */ public class FileSpanExporter implements SpanExporter { - public static final String TRACING_LOG_PREFIX = "tracing_log"; + static final String TRACING_LOG_PREFIX = "tracing_log"; private static final Logger TRACING_LOGGER = LogManager.getLogger(TRACING_LOG_PREFIX); private final Logger DEFAULT_LOGGER = LogManager.getLogger(FileSpanExporter.class); private final String FIELD_SEPARATOR = "\t"; private final AtomicBoolean isShutdown = new AtomicBoolean(); + /** + * No-args constructor + */ + public FileSpanExporter() {} + @Override public CompletableResultCode export(Collection spans) { if (isShutdown.get()) { diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java new file mode 100644 index 0000000000000..b5815891f05f6 --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains span exporters + */ +package org.opensearch.tracing.exporter; From a2dd91d9f967c8e20e733d959673e20923a13b84 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 29 May 2023 20:26:05 +0530 Subject: [PATCH 04/38] Add request tracing framework Signed-off-by: suranjay --- .../tracing/OTelTracerModulePlugin.java | 14 ++++++++++---- .../common/settings/ClusterSettings.java | 18 ++++++++++-------- .../common/settings/FeatureFlagSettings.java | 3 ++- .../opensearch/common/util/FeatureFlags.java | 7 +++++++ .../main/java/org/opensearch/node/Node.java | 17 +++++++++++------ 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java index 845028cf9c7b9..dc5790ba984e0 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.OpenTelemetry; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.TracerPlugin; import org.opensearch.threadpool.ThreadPool; @@ -18,6 +19,8 @@ import java.util.Map; import java.util.function.Supplier; +import static org.opensearch.common.util.FeatureFlags.TRACER; + /** * Tracer plugin based on Otel */ @@ -32,10 +35,13 @@ public OTelTracerModulePlugin() {} @Override public Settings additionalSettings() { - return Settings.builder() - // set Otel tracer as default tracer - .put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) - .build(); + if (FeatureFlags.isEnabled(TRACER)) { + return Settings.builder() + // set Otel tracer as default tracer + .put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) + .build(); + } + return Settings.EMPTY; } @Override diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 1be07a7c29675..9b0f98a8eaaaf 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -651,15 +651,8 @@ public void apply(Settings value, Settings current, Settings previous) { RemoteRefreshSegmentPressureSettings.MIN_CONSECUTIVE_FAILURES_LIMIT, RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_MOVING_AVERAGE_WINDOW_SIZE, RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_PER_SEC_MOVING_AVERAGE_WINDOW_SIZE, - RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE, + RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE - // Settings related to Tracing framework - TracerSettings.TRACER_LEVEL_SETTING, - TracerSettings.TRACER_EXPORTER_DELAY_SETTING, - TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, - TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, - TracerModule.TRACER_DEFAULT_TYPE_SETTING, - TracerModule.TRACER_TYPE_SETTING ) ) ); @@ -678,6 +671,15 @@ public void apply(Settings value, Settings current, Settings previous) { IndicesService.CLUSTER_REMOTE_STORE_REPOSITORY_SETTING, IndicesService.CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING, IndicesService.CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING + ), + List.of(FeatureFlags.TRACER), + List.of( + TracerSettings.TRACER_LEVEL_SETTING, + TracerSettings.TRACER_EXPORTER_DELAY_SETTING, + TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, + TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, + TracerModule.TRACER_TYPE_SETTING, + TracerModule.TRACER_DEFAULT_TYPE_SETTING ) ); } diff --git a/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java b/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java index 19a5808579d50..61b0cfb7dab88 100644 --- a/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java @@ -39,7 +39,8 @@ protected FeatureFlagSettings( FeatureFlags.EXTENSIONS_SETTING, FeatureFlags.IDENTITY_SETTING, FeatureFlags.SEARCH_PIPELINE_SETTING, - FeatureFlags.CONCURRENT_SEGMENT_SEARCH_SETTING + FeatureFlags.CONCURRENT_SEGMENT_SEARCH_SETTING, + FeatureFlags.TRACER_SETTING ) ) ); diff --git a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java index a26b4006bb31e..ee1e4dbe19759 100644 --- a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java +++ b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java @@ -63,6 +63,11 @@ public class FeatureFlags { */ public static final String CONCURRENT_SEGMENT_SEARCH = "opensearch.experimental.feature.concurrent_segment_search.enabled"; + /** + * Gates the functionality of tracing framework. + */ + public static final String TRACER = "opensearch.experimental.feature.tracer.enabled"; + /** * Should store the settings from opensearch.yml. */ @@ -105,6 +110,8 @@ public static boolean isEnabled(String featureFlagName) { public static final Setting IDENTITY_SETTING = Setting.boolSetting(IDENTITY, false, Property.NodeScope); + public static final Setting TRACER_SETTING = Setting.boolSetting(TRACER, false, Property.NodeScope); + public static final Setting CONCURRENT_SEGMENT_SEARCH_SETTING = Setting.boolSetting( CONCURRENT_SEGMENT_SEARCH, false, diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index bd50f6521608d..3e1f5679bf4db 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -256,6 +256,7 @@ import static java.util.stream.Collectors.toList; import static org.opensearch.common.util.FeatureFlags.SEARCH_PIPELINE; +import static org.opensearch.common.util.FeatureFlags.TRACER; import static org.opensearch.env.NodeEnvironment.collectFileCacheDataPath; import static org.opensearch.index.ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY; @@ -1012,11 +1013,13 @@ protected Node( searchModule.getIndexSearcherExecutor(threadPool) ); - final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); - List tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class); - TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings); - TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector()); - resourcesToClose.add(TracerManager::closeTracer); + if (FeatureFlags.isEnabled(TRACER)) { + final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); + List tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class); + TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings); + TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector()); + resourcesToClose.add(TracerManager::closeTracer); + } final List> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class) .stream() @@ -1475,7 +1478,9 @@ public synchronized void close() throws IOException { toClose.add(() -> stopWatch.stop().start("node_environment")); toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(stopWatch::stop); - toClose.add(TracerManager::closeTracer); + if (FeatureFlags.isEnabled(TRACER)) { + toClose.add(TracerManager::closeTracer); + } if (logger.isTraceEnabled()) { toClose.add(() -> logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint())); From d8bfde9af39447a378c8c60341907ccbb09955cc Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 30 May 2023 08:58:39 +0530 Subject: [PATCH 05/38] Address PR comments Signed-off-by: suranjay --- buildSrc/version.properties | 2 +- modules/tracer-otel/build.gradle | 28 ++----- .../opentelemetry-api-1.23.1.jar.sha1 | 1 - .../opentelemetry-api-1.26.0.jar.sha1 | 1 + ...entelemetry-api-logs-1.23.1-alpha.jar.sha1 | 1 - ...entelemetry-api-logs-1.26.0-alpha.jar.sha1 | 1 + .../opentelemetry-context-1.23.1.jar.sha1 | 1 - .../opentelemetry-context-1.26.0.jar.sha1 | 1 + .../opentelemetry-sdk-1.23.1.jar.sha1 | 1 - .../opentelemetry-sdk-1.26.0.jar.sha1 | 1 + .../opentelemetry-sdk-common-1.23.1.jar.sha1 | 1 - .../opentelemetry-sdk-common-1.26.0.jar.sha1 | 1 + ...entelemetry-sdk-logs-1.23.1-alpha.jar.sha1 | 1 - ...entelemetry-sdk-logs-1.26.0-alpha.jar.sha1 | 1 + .../opentelemetry-sdk-metrics-1.23.1.jar.sha1 | 1 - .../opentelemetry-sdk-metrics-1.26.0.jar.sha1 | 1 + .../opentelemetry-sdk-trace-1.23.1.jar.sha1 | 1 - .../opentelemetry-sdk-trace-1.26.0.jar.sha1 | 1 + ...pentelemetry-semconv-1.23.1-alpha.jar.sha1 | 1 - ...pentelemetry-semconv-1.26.0-alpha.jar.sha1 | 1 + .../tracing/OTelResourceProvider.java | 2 +- .../{DefaultSpan.java => OTelSpan.java} | 4 +- .../{DefaultTracer.java => OTelTracer.java} | 76 +++++++++---------- ...tor.java => OTelTracerHeaderInjector.java} | 4 +- .../tracing/OTelTracerModulePlugin.java | 4 +- .../org/opensearch/tracing/TracerUtils.java | 12 +-- .../plugin-metadata/plugin-security.policy | 24 ------ ...tTracerTests.java => OTelTracerTests.java} | 18 ++--- .../opensearch/tracing/TracerUtilsTests.java | 4 +- .../tracing/exporter/MockAppender.java | 24 ------ server/build.gradle | 8 +- .../java/org/opensearch/tracing/Level.java | 6 +- .../java/org/opensearch/tracing/Tracer.java | 10 +-- .../org/opensearch/tracing/TracerModule.java | 14 +--- .../opensearch/tracing/noop/NoopTracer.java | 10 +-- 35 files changed, 94 insertions(+), 174 deletions(-) delete mode 100644 modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 delete mode 100644 modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 create mode 100644 modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 rename modules/tracer-otel/src/main/java/org/opensearch/tracing/{DefaultSpan.java => OTelSpan.java} (88%) rename modules/tracer-otel/src/main/java/org/opensearch/tracing/{DefaultTracer.java => OTelTracer.java} (73%) rename modules/tracer-otel/src/main/java/org/opensearch/tracing/{OtelTracerHeaderInjector.java => OTelTracerHeaderInjector.java} (85%) rename modules/tracer-otel/src/test/java/org/opensearch/tracing/{DefaultTracerTests.java => OTelTracerTests.java} (87%) diff --git a/buildSrc/version.properties b/buildSrc/version.properties index 2859cea764807..8a715213dfe03 100644 --- a/buildSrc/version.properties +++ b/buildSrc/version.properties @@ -59,4 +59,4 @@ bytebuddy = 1.14.3 jmh = 1.35 # opentelemetry dependencies -opentelemetry = 1.23.1 +opentelemetry = 1.26.0 diff --git a/modules/tracer-otel/build.gradle b/modules/tracer-otel/build.gradle index 5413d4a4d3990..3bf6d842469ff 100644 --- a/modules/tracer-otel/build.gradle +++ b/modules/tracer-otel/build.gradle @@ -4,28 +4,6 @@ * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ import org.apache.tools.ant.taskdefs.condition.Os @@ -64,6 +42,10 @@ thirdPartyAudit { ignoreMissingClasses( 'io.opentelemetry.api.events.EventEmitter', 'io.opentelemetry.api.events.EventEmitterBuilder', - 'io.opentelemetry.api.events.EventEmitterProvider' + 'io.opentelemetry.api.events.EventEmitterProvider', + 'io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder', + 'io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder', + 'io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer' + ) } diff --git a/modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 deleted file mode 100644 index 77da8b4517207..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-api-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -5d32a15207c1ce0c6d18247c66074bc5f0f77aae \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..da3abcc8f70d2 --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 @@ -0,0 +1 @@ +7ee1ccca95155e4640094ba8dfbd0bb8c1709c83 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 deleted file mode 100644 index fd7b2fdb4090a..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-api-logs-1.23.1-alpha.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -bb1d7a60ba642d5b280c17825dae1642c04f0a9f \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 new file mode 100644 index 0000000000000..2c233d785dcb2 --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 @@ -0,0 +1 @@ +1b0b6c1a20da0f841634d4f736e331aa4871a4db \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 deleted file mode 100644 index e561e76c5a557..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-context-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -be63aa23ebc7fbf4f9aa46c03855e7c784a334fc \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..01d9fd732249b --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 @@ -0,0 +1 @@ +42991f523a7a10761213e2f11633c67c8beaed88 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 deleted file mode 100644 index d7f5d66e39393..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-sdk-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -071ebe12b1f42d4ec5da0c46443211eea53678d7 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..dc9946de3b160 --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 @@ -0,0 +1 @@ +79a86f258ede8625627e8fbdff07d1149c88a8e6 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 deleted file mode 100644 index 7622c3ba0db58..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -0a4510bbeb832bb21973d70e7ee02bbd6d15a1ba \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..2bd3e60a1faf6 --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 @@ -0,0 +1 @@ +b42359d2232f8d802d55153be5330b1d9e21ee15 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 deleted file mode 100644 index 0779c8a26c02f..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.23.1-alpha.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -51bd87aea57262134d1190903a98c4a4fe70a8ec \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 new file mode 100644 index 0000000000000..90bb8202c4c9d --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 @@ -0,0 +1 @@ +a8abeaee240291cce9067f07569f151d11a6275a \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 deleted file mode 100644 index db9ef241fcf05..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -0d2810c28865811662e003752d432a18c9a9a274 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..62396a603423f --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 @@ -0,0 +1 @@ +8c4af22d7d92a3a79714be3f79724b0ab774ba9e \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 deleted file mode 100644 index d839f9ced343e..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.23.1.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -cf84c1593b0f142eb6713df19e31203970ad1883 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..0fcebee353105 --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 @@ -0,0 +1 @@ +fcc5785b2cf2be897f31b927e24b53e46e377388 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 deleted file mode 100644 index eb8620961adbe..0000000000000 --- a/modules/tracer-otel/licenses/opentelemetry-semconv-1.23.1-alpha.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -e5fb9ca7332fca0be964cbbfd17b1987166c0c75 \ No newline at end of file diff --git a/modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 b/modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 new file mode 100644 index 0000000000000..47c7ece8c9f6c --- /dev/null +++ b/modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 @@ -0,0 +1 @@ +1f4f963673f8209208f868666cd43e79b9a2dd15 \ No newline at end of file diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java index b2bea01cc16df..c0084e3830e9f 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java @@ -24,7 +24,7 @@ /** * This class encapsulates all OpenTelemetry related resources */ -class OTelResourceProvider { +final class OTelResourceProvider { private static final ContextPropagators contextPropagators; private static volatile OpenTelemetry OPEN_TELEMETRY; diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java similarity index 88% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java index 77744c4101ae7..4af43d6d666e9 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultSpan.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java @@ -14,14 +14,14 @@ * Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span * lifecycle management by delegating calls to it. */ -class DefaultSpan implements Span { +class OTelSpan implements Span { private final String spanName; private final io.opentelemetry.api.trace.Span otelSpan; private final Span parentSpan; private final Level level; - public DefaultSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { + public OTelSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { this.spanName = spanName; this.otelSpan = span; this.parentSpan = parentSpan; diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java similarity index 73% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java index c4a06bc5f73bf..7063e471294ae 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/DefaultTracer.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java @@ -29,16 +29,16 @@ * It internally uses OpenTelemetry tracer. * */ -public class DefaultTracer implements Tracer { +public class OTelTracer implements Tracer { - private static final Logger logger = LogManager.getLogger(DefaultTracer.class); + private static final Logger logger = LogManager.getLogger(OTelTracer.class); private static final String TRACE_ID = "trace_id"; private static final String SPAN_ID = "span_id"; private static final String SPAN_NAME = "span_name"; private static final String PARENT_SPAN_ID = "p_span_id"; private static final String THREAD_NAME = "th_name"; private static final String PARENT_SPAN_NAME = "p_span_name"; - private static final String ROOT_SPAN = "RootSpan"; + private static final String ROOT_SPAN = "root_span"; private final ThreadPool threadPool; private final TracerSettings tracerSettings; @@ -52,7 +52,7 @@ public class DefaultTracer implements Tracer { * @param threadPool Thread pool * @param tracerSettings tracer related settings */ - public DefaultTracer(OpenTelemetry openTelemetry, ThreadPool threadPool, TracerSettings tracerSettings) { + public OTelTracer(OpenTelemetry openTelemetry, ThreadPool threadPool, TracerSettings tracerSettings) { this.openTelemetry = openTelemetry; this.otelTracer = openTelemetry.getTracer("os-tracer"); this.threadPool = threadPool; @@ -76,31 +76,31 @@ public void endSpan() { } @Override - public void addAttribute(String key, String value) { + public void addSpanAttribute(String key, String value) { addSingleAttribute(AttributeKey.stringKey(key), value); } @Override - public void addAttribute(String key, long value) { + public void addSpanAttribute(String key, long value) { addSingleAttribute(AttributeKey.longKey(key), value); } @Override - public void addAttribute(String key, double value) { + public void addSpanAttribute(String key, double value) { addSingleAttribute(AttributeKey.doubleKey(key), value); } @Override - public void addAttribute(String key, boolean value) { + public void addSpanAttribute(String key, boolean value) { addSingleAttribute(AttributeKey.booleanKey(key), value); } @Override - public void addEvent(String event) { + public void addSpanEvent(String event) { Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof DefaultSpan && ((DefaultSpan) currentSpan).getOtelSpan() != null) { - ((DefaultSpan) currentSpan).getOtelSpan().addEvent(event); + if (currentSpan instanceof OTelSpan && ((OTelSpan) currentSpan).getOtelSpan() != null) { + ((OTelSpan) currentSpan).getOtelSpan().addEvent(event); } } @@ -125,7 +125,7 @@ private Span spanFromHeader() { Context context = TracerUtils.extractTracerContextFromHeader(threadPool.getThreadContext().getHeaders()); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new DefaultSpan(ROOT_SPAN, span, null, Level.ROOT); + return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); } return null; } @@ -142,9 +142,9 @@ private Span createSpan(String spanName, Span parentSpan, Level level) { } private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { - DefaultSpan parentDefaultSpan = getLastValidSpanInChain(parentSpan); - io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentDefaultSpan); - Span span = new DefaultSpan(spanName, otelSpan, parentSpan, level); + OTelSpan parentOTelSpan = getLastValidSpanInChain(parentSpan); + io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentOTelSpan); + Span span = new OTelSpan(spanName, otelSpan, parentSpan, level); logger.trace( "Starting OtelSpan spanId:{} name:{}: traceId:{}", otelSpan.getSpanContext().getSpanId(), @@ -159,23 +159,23 @@ private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { return new NoopSpan(spanName, parentSpan, level); } - private DefaultSpan getLastValidSpanInChain(Span parentSpan) { + private OTelSpan getLastValidSpanInChain(Span parentSpan) { while (parentSpan instanceof NoopSpan) { parentSpan = parentSpan.getParentSpan(); } - return (DefaultSpan) parentSpan; + return (OTelSpan) parentSpan; } // visible for testing - io.opentelemetry.api.trace.Span createOtelSpan(String spanName, DefaultSpan parentDefaultSpan) { - return parentDefaultSpan == null + io.opentelemetry.api.trace.Span createOtelSpan(String spanName, OTelSpan parentOTelSpan) { + return parentOTelSpan == null ? otelTracer.spanBuilder(spanName).startSpan() - : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentDefaultSpan.getOtelSpan())).startSpan(); + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentOTelSpan.getOtelSpan())).startSpan(); } private boolean isLevelEnabled(Level level) { Level configuredLevel = tracerSettings.getTracerLevel(); - return level.isHigher(configuredLevel); + return level.isHigherOrEqual(configuredLevel); } private void setCurrentSpanInContext(Span span) { @@ -192,45 +192,45 @@ private void setCurrentSpanInContext(Span span) { } private void endSpan(Span span) { - if (span instanceof DefaultSpan && ((DefaultSpan) span).getOtelSpan() != null) { - DefaultSpan defaultSpan = (DefaultSpan) span; + if (span instanceof OTelSpan && ((OTelSpan) span).getOtelSpan() != null) { + OTelSpan oTelSpan = (OTelSpan) span; logger.trace( "Ending span spanId:{} name:{}: traceId:{}", - defaultSpan.getSpanContext().getSpanId(), + oTelSpan.getSpanContext().getSpanId(), span.getSpanName(), - defaultSpan.getSpanContext().getTraceId() + oTelSpan.getSpanContext().getTraceId() ); - defaultSpan.getOtelSpan().end(); + oTelSpan.getOtelSpan().end(); } else { logger.trace("Ending noop span name:{}", span.getSpanName()); } } private void setSpanAttributes(Span span) { - if (span instanceof DefaultSpan) { - addDefaultAttributes((DefaultSpan) span); + if (span instanceof OTelSpan) { + addDefaultAttributes((OTelSpan) span); } } private void addSingleAttribute(AttributeKey key, T value) { Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof DefaultSpan && ((DefaultSpan) currentSpan).getOtelSpan() != null) { - ((DefaultSpan) currentSpan).getOtelSpan().setAttribute(key, value); + if (currentSpan instanceof OTelSpan && ((OTelSpan) currentSpan).getOtelSpan() != null) { + ((OTelSpan) currentSpan).getOtelSpan().setAttribute(key, value); } } - private void addDefaultAttributes(DefaultSpan defaultSpan) { - if (defaultSpan != null) { - addSingleAttribute(AttributeKey.stringKey(SPAN_ID), defaultSpan.getSpanContext().getSpanId()); - addSingleAttribute(AttributeKey.stringKey(TRACE_ID), defaultSpan.getSpanContext().getTraceId()); - addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), defaultSpan.getSpanName()); + private void addDefaultAttributes(OTelSpan oTelSpan) { + if (oTelSpan != null) { + addSingleAttribute(AttributeKey.stringKey(SPAN_ID), oTelSpan.getSpanContext().getSpanId()); + addSingleAttribute(AttributeKey.stringKey(TRACE_ID), oTelSpan.getSpanContext().getTraceId()); + addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), oTelSpan.getSpanName()); addSingleAttribute(AttributeKey.stringKey(THREAD_NAME), Thread.currentThread().getName()); - if (defaultSpan.getParentSpan() != null && defaultSpan.getParentSpan() instanceof DefaultSpan) { + if (oTelSpan.getParentSpan() != null && oTelSpan.getParentSpan() instanceof OTelSpan) { addSingleAttribute( AttributeKey.stringKey(PARENT_SPAN_ID), - ((DefaultSpan) defaultSpan.getParentSpan()).getSpanContext().getSpanId() + ((OTelSpan) oTelSpan.getParentSpan()).getSpanContext().getSpanId() ); - addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), defaultSpan.getParentSpan().getSpanName()); + addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), oTelSpan.getParentSpan().getSpanName()); } } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java similarity index 85% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java rename to modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java index 1b4b2682a11cd..7bdf9fc5dc3ad 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTracerHeaderInjector.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java @@ -14,11 +14,11 @@ /** * Otel based header injector. This adds Otel headers to facilitate context propagation. */ -public class OtelTracerHeaderInjector implements TracerHeaderInjector { +public class OTelTracerHeaderInjector implements TracerHeaderInjector { /** * No-args constructor */ - public OtelTracerHeaderInjector() {} + public OTelTracerHeaderInjector() {} @Override public BiConsumer, Map> injectHeader() { diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java index dc5790ba984e0..6f1a0c4e1c4d8 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java @@ -51,11 +51,11 @@ public Map> getTracers(ThreadPool threadPool, TracerSet @Override public Map getHeaderInjectors() { - return Collections.singletonMap(OTEL_TRACER_NAME, new OtelTracerHeaderInjector()); + return Collections.singletonMap(OTEL_TRACER_NAME, new OTelTracerHeaderInjector()); } private Tracer createDefaultTracer(ThreadPool threadPool, TracerSettings tracerSettings) { OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); - return new DefaultTracer(openTelemetry, threadPool, tracerSettings); + return new OTelTracer(openTelemetry, threadPool, tracerSettings); } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java index d1eadecba3bed..3360be34fbdd3 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java @@ -56,10 +56,10 @@ public static final BiConsumer, Map> addTrac if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { SpanHolder spanHolder = (SpanHolder) transientHeaders.get(CURRENT_SPAN); Span currentSpan = spanHolder.getSpan(); - DefaultSpan defaultSpan = getLastValidSpanInChain(currentSpan); + OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); OTelResourceProvider.getContextPropagators() .getTextMapPropagator() - .inject(context(defaultSpan), requestHeaders, TEXT_MAP_SETTER); + .inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); } }; } @@ -72,14 +72,14 @@ public static Context extractTracerContextFromHeader(Map headers return OTelResourceProvider.getContextPropagators().getTextMapPropagator().extract(Context.current(), headers, TEXT_MAP_GETTER); } - private static Context context(DefaultSpan defaultSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(defaultSpan.getSpanContext())); + private static Context context(OTelSpan oTelSpan) { + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getSpanContext())); } - private static DefaultSpan getLastValidSpanInChain(Span span) { + private static OTelSpan getLastValidSpanInChain(Span span) { while (span instanceof NoopSpan) { span = span.getParentSpan(); } - return (DefaultSpan) span; + return (OTelSpan) span; } } diff --git a/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy b/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy index ac07c2a265bd8..0f556121915bb 100644 --- a/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy +++ b/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy @@ -6,30 +6,6 @@ * compatible open source license. */ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - grant { }; diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java similarity index 87% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java rename to modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java index 71c6ed6388d7c..565ccd0ef0f85 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/DefaultTracerTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java @@ -28,7 +28,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -public class DefaultTracerTests extends OpenSearchTestCase { +public class OTelTracerTests extends OpenSearchTestCase { private ThreadPool threadPool; @@ -36,7 +36,7 @@ public class DefaultTracerTests extends OpenSearchTestCase { private TracerSettings tracerSettings; - private ArgumentCaptor captor; + private ArgumentCaptor captor; private SpanBuilder mockSpanBuilder; @@ -56,7 +56,7 @@ public void tearDown() throws Exception { } public void testStartAndEndSpans() { - DefaultTracer tracer = new DefaultTracer(mock(OpenTelemetry.class), threadPool, mock(TracerSettings.class)); + OTelTracer tracer = new OTelTracer(mock(OpenTelemetry.class), threadPool, mock(TracerSettings.class)); tracer.startSpan("foo", Level.INFO); assertEquals("foo", tracer.getCurrentSpan().getSpanName()); @@ -65,7 +65,7 @@ public void testStartAndEndSpans() { } public void testStartSpanAndEndWithNoopSpans() { - DefaultTracer tracer = spy(new DefaultTracer(openTelemetry, threadPool, tracerSettings)); + OTelTracer tracer = spy(new OTelTracer(openTelemetry, threadPool, tracerSettings)); tracer.startSpan("span1", Level.ROOT); tracer.startSpan("span2", Level.TERSE); @@ -77,7 +77,7 @@ public void testStartSpanAndEndWithNoopSpans() { verify(tracer, times(4)).createOtelSpan(any(), captor.capture()); verify(mockSpanBuilder, times(4)).startSpan(); assertEquals("span4", tracer.getCurrentSpan().getSpanName()); - DefaultSpan value = captor.getValue(); + OTelSpan value = captor.getValue(); assertEquals("span3", value.getSpanName()); tracer.endSpan(); assertEquals("noop-span-2", tracer.getCurrentSpan().getSpanName()); @@ -97,14 +97,14 @@ public void testStartSpanAndEndWithNoopSpans() { public void testAddEvent() { ArgumentCaptor stringCaptorValues = ArgumentCaptor.forClass(String.class); - DefaultTracer tracer = new DefaultTracer(openTelemetry, threadPool, tracerSettings); + OTelTracer tracer = new OTelTracer(openTelemetry, threadPool, tracerSettings); tracer.startSpan("foo", Level.INFO); - tracer.addEvent("fooEvent"); + tracer.addSpanEvent("fooEvent"); tracer.endSpan(); tracer.startSpan("bar", Level.DEBUG); - tracer.addEvent("fooEvent"); + tracer.addSpanEvent("fooEvent"); tracer.endSpan(); verify(mockOtelSpan, times(1)).addEvent(stringCaptorValues.capture()); @@ -118,7 +118,7 @@ private void setupMock() { openTelemetry = mock(OpenTelemetry.class); Tracer mockTracer = mock(Tracer.class); when(openTelemetry.getTracer(any(String.class))).thenReturn(mockTracer); - captor = ArgumentCaptor.forClass(DefaultSpan.class); + captor = ArgumentCaptor.forClass(OTelSpan.class); mockSpanBuilder = mock(SpanBuilder.class); mockOtelSpan = mock(io.opentelemetry.api.trace.Span.class); when(mockOtelSpan.getSpanContext()).thenReturn(mock(SpanContext.class)); diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java index c943e7645537d..da7bac06b7e2f 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java @@ -31,7 +31,7 @@ public class TracerUtilsTests extends OpenSearchTestCase { public void testAddTracerContextToHeader() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - DefaultSpan span = new DefaultSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); SpanHolder spanHolder = new SpanHolder(span); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); @@ -42,7 +42,7 @@ public void testAddTracerContextToHeader() { public void testAddTracerContextToHeaderWithNoopSpan() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - DefaultSpan span = new DefaultSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); SpanHolder spanHolder = new SpanHolder(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java index b74d2cc8c0820..16f7cd88e4236 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java @@ -6,30 +6,6 @@ * compatible open source license. */ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - package org.opensearch.tracing.exporter; import org.apache.logging.log4j.core.LogEvent; diff --git a/server/build.gradle b/server/build.gradle index 62c0002dc1398..36b6f465bd80b 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -333,10 +333,7 @@ tasks.named("thirdPartyAudit").configure { 'com.google.common.geometry.S2Projections', 'com.google.common.geometry.S2Point', 'com.google.common.geometry.S2$Metric', - 'com.google.common.geometry.S2LatLng', - - - + 'com.google.common.geometry.S2LatLng' ) ignoreViolations( 'com.google.protobuf.MessageSchema', @@ -345,8 +342,7 @@ tasks.named("thirdPartyAudit").configure { 'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor', 'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor', 'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor', - 'com.google.protobuf.UnsafeUtil$MemoryAccessor', - + 'com.google.protobuf.UnsafeUtil$MemoryAccessor' ) } diff --git a/server/src/main/java/org/opensearch/tracing/Level.java b/server/src/main/java/org/opensearch/tracing/Level.java index 7e20483f1038d..f2a59df04a64b 100644 --- a/server/src/main/java/org/opensearch/tracing/Level.java +++ b/server/src/main/java/org/opensearch/tracing/Level.java @@ -89,11 +89,11 @@ public int getValue() { } /** - * Checks if the current level's value is higher than the given level + * Checks if the current level's value is equal or higher than the given level * @param level to compare - * @return true if the current level's value is higher than given level's value, false otherwise + * @return true if the current level's value is equal or higher than given level's value, false otherwise */ - public boolean isHigher(Level level) { + public boolean isHigherOrEqual(Level level) { if (level != null) { return this.value >= level.value; } diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/server/src/main/java/org/opensearch/tracing/Tracer.java index 3c6230681e7db..5f1221c987c0b 100644 --- a/server/src/main/java/org/opensearch/tracing/Tracer.java +++ b/server/src/main/java/org/opensearch/tracing/Tracer.java @@ -47,7 +47,7 @@ public interface Tracer extends Closeable { * @param key attribute key * @param value attribute value */ - void addAttribute(String key, String value); + void addSpanAttribute(String key, String value); /** * Adds long attribute to the current active {@link Span}. @@ -55,7 +55,7 @@ public interface Tracer extends Closeable { * @param key attribute key * @param value attribute value */ - void addAttribute(String key, long value); + void addSpanAttribute(String key, long value); /** * Adds double attribute to the current active {@link Span}. @@ -63,7 +63,7 @@ public interface Tracer extends Closeable { * @param key attribute key * @param value attribute value */ - void addAttribute(String key, double value); + void addSpanAttribute(String key, double value); /** * Adds boolean attribute to the current active {@link Span}. @@ -71,12 +71,12 @@ public interface Tracer extends Closeable { * @param key attribute key * @param value attribute value */ - void addAttribute(String key, boolean value); + void addSpanAttribute(String key, boolean value); /** * Adds an event to the current active {@link Span}. * * @param event event name */ - void addEvent(String event); + void addSpanEvent(String event); } diff --git a/server/src/main/java/org/opensearch/tracing/TracerModule.java b/server/src/main/java/org/opensearch/tracing/TracerModule.java index 1068820257e73..276c3441b9b86 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerModule.java +++ b/server/src/main/java/org/opensearch/tracing/TracerModule.java @@ -57,22 +57,12 @@ public TracerModule(Settings settings, List tracerPlugins, ThreadP public Supplier getTracerSupplier() { final String tracerType = getTracerType(); - - final Supplier factory = tracerFactories.get(tracerType); - /*if (factory == null) { - throw new IllegalStateException("Unsupported tracer.type [" + tracerType + "]"); - }*/ - return factory; + return tracerFactories.get(tracerType); } public TracerHeaderInjector getTracerHeaderInjector() { final String tracerType = getTracerType(); - - final TracerHeaderInjector tracerHeaderInjector = tracerHeaderInjectors.get(tracerType); - /*if (tracerHeaderInjector == null) { - throw new IllegalStateException("Unsupported tracer.type [" + tracerType + "]"); - }*/ - return tracerHeaderInjector; + return tracerHeaderInjectors.get(tracerType); } private String getTracerType() { diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java index 73f0a7e1a88de..59a325462fcfe 100644 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java @@ -34,7 +34,7 @@ public void endSpan() {} * @param value attribute value */ @Override - public void addAttribute(String key, String value) { + public void addSpanAttribute(String key, String value) { } @@ -43,7 +43,7 @@ public void addAttribute(String key, String value) { * @param value attribute value */ @Override - public void addAttribute(String key, long value) { + public void addSpanAttribute(String key, long value) { } @@ -52,7 +52,7 @@ public void addAttribute(String key, long value) { * @param value attribute value */ @Override - public void addAttribute(String key, double value) { + public void addSpanAttribute(String key, double value) { } @@ -61,12 +61,12 @@ public void addAttribute(String key, double value) { * @param value attribute value */ @Override - public void addAttribute(String key, boolean value) { + public void addSpanAttribute(String key, boolean value) { } @Override - public void addEvent(String event) { + public void addSpanEvent(String event) { } From ddfdbf690cd65e5feae84e4e2a82a867939219df Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 30 May 2023 12:40:39 +0530 Subject: [PATCH 06/38] Fixed test Signed-off-by: suranjay --- modules/tracer-otel/build.gradle | 1 - .../opensearch/tracing/OTelTracerTests.java | 14 +++++++++--- .../tracing/TracerManagerTests.java | 22 ++++++++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/modules/tracer-otel/build.gradle b/modules/tracer-otel/build.gradle index 3bf6d842469ff..2b20b05137760 100644 --- a/modules/tracer-otel/build.gradle +++ b/modules/tracer-otel/build.gradle @@ -46,6 +46,5 @@ thirdPartyAudit { 'io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder', 'io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder', 'io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer' - ) } diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java index 565ccd0ef0f85..8ee4728d47d12 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java @@ -16,11 +16,17 @@ import org.junit.Before; import org.mockito.ArgumentCaptor; import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; @@ -61,7 +67,7 @@ public void testStartAndEndSpans() { tracer.startSpan("foo", Level.INFO); assertEquals("foo", tracer.getCurrentSpan().getSpanName()); tracer.endSpan(); - assertEquals("RootSpan", tracer.getCurrentSpan().getSpanName()); + assertEquals("root_span", tracer.getCurrentSpan().getSpanName()); } public void testStartSpanAndEndWithNoopSpans() { @@ -90,7 +96,7 @@ public void testStartSpanAndEndWithNoopSpans() { tracer.endSpan(); assertEquals("span1", tracer.getCurrentSpan().getSpanName()); tracer.endSpan(); - assertEquals("RootSpan", tracer.getCurrentSpan().getSpanName()); + assertEquals("root_span", tracer.getCurrentSpan().getSpanName()); verify(mockOtelSpan, times(4)).end(); } @@ -112,8 +118,10 @@ public void testAddEvent() { } private void setupMock() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); tracerSettings = new TracerSettings(settings, clusterSettings); openTelemetry = mock(OpenTelemetry.class); Tracer mockTracer = mock(Tracer.class); diff --git a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java index 01e7bb7c0116f..87dfd407207a7 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java @@ -11,10 +11,16 @@ import org.junit.After; import org.junit.Before; import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.tracing.noop.NoopTracer; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import static org.mockito.Mockito.mock; public class TracerManagerTests extends OpenSearchTestCase { @@ -36,10 +42,7 @@ public void testGetTracerWithUninitializedTracerFactory() { public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); - TracerSettings tracerSettings = new TracerSettings( - settings, - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); TracerManager.initTracerManager(tracerSettings, null, null); Tracer tracer = TracerManager.getTracer(); @@ -48,14 +51,17 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - TracerSettings tracerSettings = new TracerSettings( - settings, - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); TracerManager.initTracerManager(tracerSettings, () -> mock(Tracer.class), null); Tracer tracer = TracerManager.getTracer(); assertFalse(tracer instanceof NoopTracer); } + + private Set> getClusterSettings() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + return allTracerSettings; + } } From bf36b6b4480d533c88bfe5ea1673151ebe741b73 Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 30 May 2023 17:30:47 +0530 Subject: [PATCH 07/38] Add unit tests Signed-off-by: suranjay --- .../tracing/OTelTracerModulePlugin.java | 2 +- .../tracing/OTelTracerModulePluginTests.java | 69 +++++++++++++++++++ .../opensearch/tracing/OTelTracerTests.java | 30 +++++++- .../tracing/TracerManagerTests.java | 10 +++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java index 6f1a0c4e1c4d8..ad1ce388fe51d 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java @@ -26,7 +26,7 @@ */ public class OTelTracerModulePlugin extends Plugin implements TracerPlugin { - private static final String OTEL_TRACER_NAME = "otel"; + static final String OTEL_TRACER_NAME = "otel"; /** * No-args constructor diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java new file mode 100644 index 0000000000000..39b3b8fde37f5 --- /dev/null +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java @@ -0,0 +1,69 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.SuppressForbidden; +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.threadpool.ThreadPool; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Supplier; + +import static org.mockito.Mockito.mock; +import static org.opensearch.tracing.OTelTracerModulePlugin.OTEL_TRACER_NAME; + +public class OTelTracerModulePluginTests extends OpenSearchTestCase { + + @SuppressForbidden(reason = "manipulates system properties for testing") + public void testAdditionalSettingWithTracingFeatureDisabled() { + System.setProperty("opensearch.experimental.feature.tracer.enabled", "false"); + Settings settings = new OTelTracerModulePlugin().additionalSettings(); + + assertTrue(settings.isEmpty()); + } + + @SuppressForbidden(reason = "manipulates system properties for testing") + public void testAdditionalSettingWithTracingFeatureEnabled() { + System.setProperty("opensearch.experimental.feature.tracer.enabled", "true"); + Settings settings = new OTelTracerModulePlugin().additionalSettings(); + + assertFalse(settings.isEmpty()); + } + + public void testGetTracers() throws IOException { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); + TracerSettings tracerSettings = new TracerSettings(settings, clusterSettings); + Map> tracers = new OTelTracerModulePlugin().getTracers(mock(ThreadPool.class), tracerSettings); + + assertEquals(Set.of(OTEL_TRACER_NAME), tracers.keySet()); + Tracer tracer = tracers.get(OTEL_TRACER_NAME).get(); + assertTrue(tracer instanceof OTelTracer); + tracer.close(); + + } + + public void testGetHeaderInjectors() { + Map injectors = new OTelTracerModulePlugin().getHeaderInjectors(); + + assertEquals(Set.of(OTEL_TRACER_NAME), injectors.keySet()); + assertTrue(injectors.get(OTEL_TRACER_NAME) instanceof OTelTracerHeaderInjector); + } + +} diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java index 8ee4728d47d12..5a00ff8d7240f 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java @@ -9,6 +9,9 @@ package org.opensearch.tracing; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.AttributeType; +import io.opentelemetry.api.internal.InternalAttributeKeyImpl; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.Tracer; @@ -28,6 +31,7 @@ import java.util.Set; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.spy; @@ -100,6 +104,27 @@ public void testStartSpanAndEndWithNoopSpans() { verify(mockOtelSpan, times(4)).end(); } + public void testAddAttribute() { + OTelTracer tracer = new OTelTracer(openTelemetry, threadPool, tracerSettings); + + tracer.startSpan("foo", Level.INFO); + tracer.addSpanAttribute("stringKey", "value"); + tracer.addSpanAttribute("longKey", 1L); + tracer.addSpanAttribute("doubleKey", 1.0); + tracer.addSpanAttribute("booleanKey", true); + tracer.endSpan(); + ArgumentCaptor> stringKeyCaptorValues = ArgumentCaptor.forClass(AttributeKey.class); + ArgumentCaptor stringValueCaptorValues = ArgumentCaptor.forClass(String.class); + + // 6 other default string attributes are added + verify(mockOtelSpan, times(1 + 6)).setAttribute(stringKeyCaptorValues.capture(), stringValueCaptorValues.capture()); + verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("longKey", AttributeType.LONG)), eq(1L)); + verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("doubleKey", AttributeType.DOUBLE)), eq(1.0)); + verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("booleanKey", AttributeType.BOOLEAN)), eq(true)); + + assertTrue(stringValueCaptorValues.getAllValues().contains("value")); + } + public void testAddEvent() { ArgumentCaptor stringCaptorValues = ArgumentCaptor.forClass(String.class); @@ -129,7 +154,10 @@ private void setupMock() { captor = ArgumentCaptor.forClass(OTelSpan.class); mockSpanBuilder = mock(SpanBuilder.class); mockOtelSpan = mock(io.opentelemetry.api.trace.Span.class); - when(mockOtelSpan.getSpanContext()).thenReturn(mock(SpanContext.class)); + SpanContext mockSpanContext = mock(SpanContext.class); + when(mockSpanContext.getSpanId()).thenReturn("span_id"); + when(mockSpanContext.getTraceId()).thenReturn("trace_id"); + when(mockOtelSpan.getSpanContext()).thenReturn(mockSpanContext); when(mockSpanBuilder.startSpan()).thenReturn(mockOtelSpan); when(mockSpanBuilder.setParent(any())).thenReturn(mockSpanBuilder); when(mockTracer.spanBuilder(any(String.class))).thenReturn(mockSpanBuilder); diff --git a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java index 87dfd407207a7..204cdf21d17c2 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java @@ -16,6 +16,7 @@ import org.opensearch.common.util.FeatureFlags; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.tracing.noop.NoopTracer; +import org.opensearch.tracing.noop.NoopTracerHeaderInjector; import java.util.HashSet; import java.util.List; @@ -59,6 +60,15 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { } + public void testGetTracerWithTracingDisabledReturnsNoopHeaderInjector() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + TracerManager.initTracerManager(tracerSettings, null, null); + + TracerHeaderInjector tracerHeaderInjector = TracerManager.getTracerHeaderInjector(); + assertTrue(tracerHeaderInjector instanceof NoopTracerHeaderInjector); + } + private Set> getClusterSettings() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); From 11c95bab909f030bb0377e7116caad30d4dca9d1 Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 31 May 2023 08:41:43 +0530 Subject: [PATCH 08/38] Refactor code Signed-off-by: suranjay --- .../tracing/OTelResourceProvider.java | 34 +-- .../java/org/opensearch/tracing/OTelSpan.java | 67 +++-- .../org/opensearch/tracing/OTelTracer.java | 238 ------------------ .../tracing/OTelTracerHeaderInjector.java | 27 -- .../tracing/OTelTracerModulePlugin.java | 14 +- .../org/opensearch/tracing/OtelTelemetry.java | 81 ++++++ .../org/opensearch/tracing/TracerUtils.java | 4 +- .../org/opensearch/tracing/OTelSpanTests.java | 92 +++++++ .../tracing/OTelTracerModulePluginTests.java | 17 +- .../opensearch/tracing/OTelTracerTests.java | 166 ------------ .../opensearch/tracing/TracerUtilsTests.java | 2 +- .../common/util/concurrent/ThreadContext.java | 4 +- .../main/java/org/opensearch/node/Node.java | 4 +- .../org/opensearch/plugins/TracerPlugin.java | 7 +- .../org/opensearch/tracing/AbstractSpan.java | 40 +++ .../org/opensearch/tracing/DefaultTracer.java | 159 ++++++++++++ .../java/org/opensearch/tracing/Span.java | 16 ++ .../org/opensearch/tracing/SpanFactory.java | 51 ++++ .../org/opensearch/tracing/Telemetry.java | 28 +++ .../java/org/opensearch/tracing/Tracer.java | 2 - .../tracing/TracerHeaderInjector.java | 21 -- .../org/opensearch/tracing/TracerManager.java | 32 +-- .../org/opensearch/tracing/TracerModule.java | 33 +-- .../org/opensearch/tracing/noop/NoopSpan.java | 52 +++- .../noop/NoopTracerHeaderInjector.java | 29 --- .../opensearch/tracing/SpanFactoryTests.java | 54 ++++ .../tracing/TracerManagerTests.java | 17 +- 27 files changed, 673 insertions(+), 618 deletions(-) delete mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java delete mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java create mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java create mode 100644 modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java delete mode 100644 modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java create mode 100644 server/src/main/java/org/opensearch/tracing/AbstractSpan.java create mode 100644 server/src/main/java/org/opensearch/tracing/DefaultTracer.java create mode 100644 server/src/main/java/org/opensearch/tracing/SpanFactory.java create mode 100644 server/src/main/java/org/opensearch/tracing/Telemetry.java delete mode 100644 server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java delete mode 100644 server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java create mode 100644 server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java index c0084e3830e9f..179f323714c12 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java @@ -35,21 +35,25 @@ final class OTelResourceProvider { static OpenTelemetry getOrCreateOpenTelemetryInstance(TracerSettings tracerSettings) { if (OPEN_TELEMETRY == null) { - Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor( - BatchSpanProcessor.builder(new FileSpanExporter()) - .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) - .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) - .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) - .build() - ) - .setResource(resource) - .build(); - OPEN_TELEMETRY = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(contextPropagators) - .buildAndRegisterGlobal(); + synchronized (OTelResourceProvider.class) { + if (OPEN_TELEMETRY == null) { + Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor( + BatchSpanProcessor.builder(new FileSpanExporter()) + .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) + .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) + .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) + .build() + ) + .setResource(resource) + .build(); + OPEN_TELEMETRY = OpenTelemetrySdk.builder() + .setTracerProvider(sdkTracerProvider) + .setPropagators(contextPropagators) + .buildAndRegisterGlobal(); + } + } } return OPEN_TELEMETRY; } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java index 4af43d6d666e9..584bbb4ab9cea 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java @@ -8,47 +8,78 @@ package org.opensearch.tracing; -import io.opentelemetry.api.trace.SpanContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span * lifecycle management by delegating calls to it. */ -class OTelSpan implements Span { +class OTelSpan extends AbstractSpan { + + private static final Logger logger = LogManager.getLogger(OTelSpan.class); - private final String spanName; private final io.opentelemetry.api.trace.Span otelSpan; - private final Span parentSpan; - private final Level level; public OTelSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { - this.spanName = spanName; + super(spanName, parentSpan, level); this.otelSpan = span; - this.parentSpan = parentSpan; - this.level = level; + logger.trace( + "Starting OtelSpan spanId:{} name:{}: traceId:{}", + otelSpan.getSpanContext().getSpanId(), + spanName, + otelSpan.getSpanContext().getTraceId() + ); } @Override - public Span getParentSpan() { - return parentSpan; + public void endSpan() { + logger.trace( + "Ending span spanId:{} name:{}: traceId:{}", + otelSpan.getSpanContext().getSpanId(), + spanName, + otelSpan.getSpanContext().getTraceId() + ); + otelSpan.end(); } @Override - public Level getLevel() { - return level; + public void addAttribute(String key, String value) { + otelSpan.setAttribute(key, value); } @Override - public String getSpanName() { - return spanName; + public void addAttribute(String key, Long value) { + otelSpan.setAttribute(key, value); } - io.opentelemetry.api.trace.Span getOtelSpan() { - return otelSpan; + @Override + public void addAttribute(String key, Double value) { + otelSpan.setAttribute(key, value); + } + + @Override + public void addAttribute(String key, Boolean value) { + otelSpan.setAttribute(key, value); + } + + @Override + public void addEvent(String event) { + otelSpan.addEvent(event); } - SpanContext getSpanContext() { - return otelSpan.getSpanContext(); + @Override + public String getTraceId() { + return otelSpan.getSpanContext().getTraceId(); + } + + @Override + public String getSpanId() { + return otelSpan.getSpanContext().getSpanId(); + } + + io.opentelemetry.api.trace.Span getOtelSpan() { + return otelSpan; } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java deleted file mode 100644 index 7063e471294ae..0000000000000 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracer.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.context.Context; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.common.util.concurrent.ThreadContext; -import org.opensearch.threadpool.ThreadPool; -import org.opensearch.tracing.noop.NoopSpan; - -import java.io.Closeable; -import java.io.IOException; -import java.util.Optional; - -/** - * - * The default tracer implementation. This class implements the basic logic for span lifecycle and its state management. - * It also handles tracing context propagation between spans. - * - * It internally uses OpenTelemetry tracer. - * - */ -public class OTelTracer implements Tracer { - - private static final Logger logger = LogManager.getLogger(OTelTracer.class); - private static final String TRACE_ID = "trace_id"; - private static final String SPAN_ID = "span_id"; - private static final String SPAN_NAME = "span_name"; - private static final String PARENT_SPAN_ID = "p_span_id"; - private static final String THREAD_NAME = "th_name"; - private static final String PARENT_SPAN_NAME = "p_span_name"; - private static final String ROOT_SPAN = "root_span"; - - private final ThreadPool threadPool; - private final TracerSettings tracerSettings; - private final io.opentelemetry.api.trace.Tracer otelTracer; - private final OpenTelemetry openTelemetry; - - /** - * Creates DefaultTracer instance - * - * @param openTelemetry Otel global Opentelemetry instance - * @param threadPool Thread pool - * @param tracerSettings tracer related settings - */ - public OTelTracer(OpenTelemetry openTelemetry, ThreadPool threadPool, TracerSettings tracerSettings) { - this.openTelemetry = openTelemetry; - this.otelTracer = openTelemetry.getTracer("os-tracer"); - this.threadPool = threadPool; - this.tracerSettings = tracerSettings; - } - - @Override - public void startSpan(String spanName, Level level) { - Span span = createSpan(spanName, getCurrentSpan(), level); - setCurrentSpanInContext(span); - setSpanAttributes(span); - } - - @Override - public void endSpan() { - Span currentSpan = getCurrentSpan(); - if (currentSpan != null) { - endSpan(currentSpan); - setCurrentSpanInContext(currentSpan.getParentSpan()); - } - } - - @Override - public void addSpanAttribute(String key, String value) { - addSingleAttribute(AttributeKey.stringKey(key), value); - } - - @Override - public void addSpanAttribute(String key, long value) { - addSingleAttribute(AttributeKey.longKey(key), value); - - } - - @Override - public void addSpanAttribute(String key, double value) { - addSingleAttribute(AttributeKey.doubleKey(key), value); - } - - @Override - public void addSpanAttribute(String key, boolean value) { - addSingleAttribute(AttributeKey.booleanKey(key), value); - } - - @Override - public void addSpanEvent(String event) { - Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof OTelSpan && ((OTelSpan) currentSpan).getOtelSpan() != null) { - ((OTelSpan) currentSpan).getOtelSpan().addEvent(event); - } - } - - @Override - public void close() { - if (openTelemetry instanceof Closeable) { - try { - ((Closeable) openTelemetry).close(); - } catch (IOException e) { - logger.warn("Error while closing tracer", e); - } - } - } - - @Override - public Span getCurrentSpan() { - Optional optionalSpanFromContext = spanFromThreadContext(); - return optionalSpanFromContext.orElse(spanFromHeader()); - } - - private Span spanFromHeader() { - Context context = TracerUtils.extractTracerContextFromHeader(threadPool.getThreadContext().getHeaders()); - if (context != null) { - io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); - } - return null; - } - - private Optional spanFromThreadContext() { - ThreadContext threadContext = threadPool.getThreadContext(); - SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); - - return (spanHolder == null) ? Optional.empty() : Optional.ofNullable(spanHolder.getSpan()); - } - - private Span createSpan(String spanName, Span parentSpan, Level level) { - return isLevelEnabled(level) ? createDefaultSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); - } - - private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { - OTelSpan parentOTelSpan = getLastValidSpanInChain(parentSpan); - io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentOTelSpan); - Span span = new OTelSpan(spanName, otelSpan, parentSpan, level); - logger.trace( - "Starting OtelSpan spanId:{} name:{}: traceId:{}", - otelSpan.getSpanContext().getSpanId(), - span.getSpanName(), - otelSpan.getSpanContext().getTraceId() - ); - return span; - } - - private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { - logger.trace("Starting Noop span name:{}", spanName); - return new NoopSpan(spanName, parentSpan, level); - } - - private OTelSpan getLastValidSpanInChain(Span parentSpan) { - while (parentSpan instanceof NoopSpan) { - parentSpan = parentSpan.getParentSpan(); - } - return (OTelSpan) parentSpan; - } - - // visible for testing - io.opentelemetry.api.trace.Span createOtelSpan(String spanName, OTelSpan parentOTelSpan) { - return parentOTelSpan == null - ? otelTracer.spanBuilder(spanName).startSpan() - : otelTracer.spanBuilder(spanName).setParent(Context.current().with(parentOTelSpan.getOtelSpan())).startSpan(); - } - - private boolean isLevelEnabled(Level level) { - Level configuredLevel = tracerSettings.getTracerLevel(); - return level.isHigherOrEqual(configuredLevel); - } - - private void setCurrentSpanInContext(Span span) { - if (span == null) { - return; - } - ThreadContext threadContext = threadPool.getThreadContext(); - SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); - if (spanHolder == null) { - threadContext.putTransient(CURRENT_SPAN, new SpanHolder(span)); - } else { - spanHolder.setSpan(span); - } - } - - private void endSpan(Span span) { - if (span instanceof OTelSpan && ((OTelSpan) span).getOtelSpan() != null) { - OTelSpan oTelSpan = (OTelSpan) span; - logger.trace( - "Ending span spanId:{} name:{}: traceId:{}", - oTelSpan.getSpanContext().getSpanId(), - span.getSpanName(), - oTelSpan.getSpanContext().getTraceId() - ); - oTelSpan.getOtelSpan().end(); - } else { - logger.trace("Ending noop span name:{}", span.getSpanName()); - } - } - - private void setSpanAttributes(Span span) { - if (span instanceof OTelSpan) { - addDefaultAttributes((OTelSpan) span); - } - } - - private void addSingleAttribute(AttributeKey key, T value) { - Span currentSpan = getCurrentSpan(); - if (currentSpan instanceof OTelSpan && ((OTelSpan) currentSpan).getOtelSpan() != null) { - ((OTelSpan) currentSpan).getOtelSpan().setAttribute(key, value); - } - } - - private void addDefaultAttributes(OTelSpan oTelSpan) { - if (oTelSpan != null) { - addSingleAttribute(AttributeKey.stringKey(SPAN_ID), oTelSpan.getSpanContext().getSpanId()); - addSingleAttribute(AttributeKey.stringKey(TRACE_ID), oTelSpan.getSpanContext().getTraceId()); - addSingleAttribute(AttributeKey.stringKey(SPAN_NAME), oTelSpan.getSpanName()); - addSingleAttribute(AttributeKey.stringKey(THREAD_NAME), Thread.currentThread().getName()); - if (oTelSpan.getParentSpan() != null && oTelSpan.getParentSpan() instanceof OTelSpan) { - addSingleAttribute( - AttributeKey.stringKey(PARENT_SPAN_ID), - ((OTelSpan) oTelSpan.getParentSpan()).getSpanContext().getSpanId() - ); - addSingleAttribute(AttributeKey.stringKey(PARENT_SPAN_NAME), oTelSpan.getParentSpan().getSpanName()); - } - } - } - -} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java deleted file mode 100644 index 7bdf9fc5dc3ad..0000000000000 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerHeaderInjector.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import java.util.Map; -import java.util.function.BiConsumer; - -/** - * Otel based header injector. This adds Otel headers to facilitate context propagation. - */ -public class OTelTracerHeaderInjector implements TracerHeaderInjector { - /** - * No-args constructor - */ - public OTelTracerHeaderInjector() {} - - @Override - public BiConsumer, Map> injectHeader() { - return TracerUtils.addTracerContextToHeader(); - } -} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java index ad1ce388fe51d..d2d9e07ca7207 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java @@ -13,7 +13,6 @@ import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.TracerPlugin; -import org.opensearch.threadpool.ThreadPool; import java.util.Collections; import java.util.Map; @@ -45,17 +44,12 @@ public Settings additionalSettings() { } @Override - public Map> getTracers(ThreadPool threadPool, TracerSettings tracerSettings) { - return Collections.singletonMap(OTEL_TRACER_NAME, () -> createDefaultTracer(threadPool, tracerSettings)); + public Map> getTelemetries(TracerSettings tracerSettings) { + return Collections.singletonMap(OTEL_TRACER_NAME, () -> getTelemetry(tracerSettings)); } - @Override - public Map getHeaderInjectors() { - return Collections.singletonMap(OTEL_TRACER_NAME, new OTelTracerHeaderInjector()); - } - - private Tracer createDefaultTracer(ThreadPool threadPool, TracerSettings tracerSettings) { + private Telemetry getTelemetry(TracerSettings tracerSettings) { OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); - return new OTelTracer(openTelemetry, threadPool, tracerSettings); + return new OtelTelemetry(openTelemetry); } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java new file mode 100644 index 0000000000000..0d7072596442d --- /dev/null +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java @@ -0,0 +1,81 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.context.Context; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * OTel based Telemetry provider + */ +public class OtelTelemetry implements Telemetry { + + private static final Logger logger = LogManager.getLogger(OtelTelemetry.class); + private static final String ROOT_SPAN = "root_span"; + + private final OpenTelemetry openTelemetry; + private final io.opentelemetry.api.trace.Tracer otelTracer; + + /** + * Creates OTel based Telemetry + * @param openTelemetry OpenTelemetry instance + */ + public OtelTelemetry(OpenTelemetry openTelemetry) { + this.openTelemetry = openTelemetry; + this.otelTracer = openTelemetry.getTracer("os-tracer"); + + } + + @Override + public void close() { + try { + ((Closeable) openTelemetry).close(); + } catch (IOException e) { + logger.warn("Error while closing Opentelemetry", e); + } + } + + @Override + public Span createSpan(String spanName, Span parentSpan, Level level) { + return createOtelSpan(spanName, parentSpan, level); + } + + private Span createOtelSpan(String spanName, Span parentSpan, Level level) { + io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentSpan); + return new OTelSpan(spanName, otelSpan, parentSpan, level); + } + + @Override + public Span extractSpanFromHeader(Map header) { + Context context = TracerUtils.extractTracerContextFromHeader(header); + if (context != null) { + io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); + return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); + } + return null; + } + + @Override + public BiConsumer, Map> injectSpanInHeader() { + return TracerUtils.addTracerContextToHeader(); + } + + io.opentelemetry.api.trace.Span createOtelSpan(String spanName, Span parentOTelSpan) { + return parentOTelSpan == null + ? otelTracer.spanBuilder(spanName).startSpan() + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getOtelSpan())).startSpan(); + } +} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java index 3360be34fbdd3..1a4b406773bcb 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java +++ b/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.function.BiConsumer; -import static org.opensearch.tracing.Tracer.CURRENT_SPAN; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; /** * Contains utils methods for tracing @@ -73,7 +73,7 @@ public static Context extractTracerContextFromHeader(Map headers } private static Context context(OTelSpan oTelSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getSpanContext())); + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); } private static OTelSpan getLastValidSpanInChain(Span span) { diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java new file mode 100644 index 0000000000000..171a5ae491cb9 --- /dev/null +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.TraceFlags; +import io.opentelemetry.api.trace.TraceState; +import org.opensearch.test.OpenSearchTestCase; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class OTelSpanTests extends OpenSearchTestCase { + + private static final String TRACE_ID = "4aa59968f31dcbff7807741afa9d7d62"; + private static final String SPAN_ID = "bea205cd25756b5e"; + + public void testEndSpanTest() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.endSpan(); + verify(mockSpan).end(); + } + + public void testAddAttributeString() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.addAttribute("key", "value"); + + verify(mockSpan).setAttribute("key", "value"); + } + + public void testAddAttributeLong() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.addAttribute("key", 1L); + + verify(mockSpan).setAttribute("key", 1L); + } + + public void testAddAttributeDouble() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.addAttribute("key", 1.0); + + verify(mockSpan).setAttribute("key", 1.0); + } + + public void testAddAttributeBoolean() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.addAttribute("key", true); + + verify(mockSpan).setAttribute("key", true); + } + + public void testAddEvent() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + oTelSpan.addEvent("eventName"); + + verify(mockSpan).addEvent("eventName"); + } + + public void testGetTraceId() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + + assertEquals(TRACE_ID, oTelSpan.getTraceId()); + } + + public void testGetSpanId() { + Span mockSpan = getMockSpan(); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + + assertEquals(SPAN_ID, oTelSpan.getSpanId()); + } + + private Span getMockSpan() { + Span mockSpan = mock(Span.class); + when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); + return mockSpan; + } +} diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java index 39b3b8fde37f5..df36122eb8c55 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java @@ -14,7 +14,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.ThreadPool; import java.io.IOException; import java.util.HashSet; @@ -23,7 +22,6 @@ import java.util.Set; import java.util.function.Supplier; -import static org.mockito.Mockito.mock; import static org.opensearch.tracing.OTelTracerModulePlugin.OTEL_TRACER_NAME; public class OTelTracerModulePluginTests extends OpenSearchTestCase { @@ -50,20 +48,13 @@ public void testGetTracers() throws IOException { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); TracerSettings tracerSettings = new TracerSettings(settings, clusterSettings); - Map> tracers = new OTelTracerModulePlugin().getTracers(mock(ThreadPool.class), tracerSettings); + Map> tracers = new OTelTracerModulePlugin().getTelemetries(tracerSettings); assertEquals(Set.of(OTEL_TRACER_NAME), tracers.keySet()); - Tracer tracer = tracers.get(OTEL_TRACER_NAME).get(); - assertTrue(tracer instanceof OTelTracer); - tracer.close(); + Telemetry telemetry = tracers.get(OTEL_TRACER_NAME).get(); + assertTrue(telemetry instanceof OtelTelemetry); + telemetry.close(); } - public void testGetHeaderInjectors() { - Map injectors = new OTelTracerModulePlugin().getHeaderInjectors(); - - assertEquals(Set.of(OTEL_TRACER_NAME), injectors.keySet()); - assertTrue(injectors.get(OTEL_TRACER_NAME) instanceof OTelTracerHeaderInjector); - } - } diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java deleted file mode 100644 index 5a00ff8d7240f..0000000000000 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerTests.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.AttributeType; -import io.opentelemetry.api.internal.InternalAttributeKeyImpl; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.Tracer; -import org.junit.After; -import org.junit.Before; -import org.mockito.ArgumentCaptor; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.TestThreadPool; -import org.opensearch.threadpool.ThreadPool; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -public class OTelTracerTests extends OpenSearchTestCase { - - private ThreadPool threadPool; - - private OpenTelemetry openTelemetry; - - private TracerSettings tracerSettings; - - private ArgumentCaptor captor; - - private SpanBuilder mockSpanBuilder; - - private io.opentelemetry.api.trace.Span mockOtelSpan; - - @Before - public void setUp() throws Exception { - super.setUp(); - setupMock(); - threadPool = new TestThreadPool("test"); - } - - @After - public void tearDown() throws Exception { - terminate(threadPool); - super.tearDown(); - } - - public void testStartAndEndSpans() { - OTelTracer tracer = new OTelTracer(mock(OpenTelemetry.class), threadPool, mock(TracerSettings.class)); - - tracer.startSpan("foo", Level.INFO); - assertEquals("foo", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("root_span", tracer.getCurrentSpan().getSpanName()); - } - - public void testStartSpanAndEndWithNoopSpans() { - OTelTracer tracer = spy(new OTelTracer(openTelemetry, threadPool, tracerSettings)); - - tracer.startSpan("span1", Level.ROOT); - tracer.startSpan("span2", Level.TERSE); - tracer.startSpan("span3", Level.INFO); - tracer.startSpan("noop-span-1", Level.DEBUG); - tracer.startSpan("noop-span-2", Level.TRACE); - tracer.startSpan("span4", Level.INFO); - - verify(tracer, times(4)).createOtelSpan(any(), captor.capture()); - verify(mockSpanBuilder, times(4)).startSpan(); - assertEquals("span4", tracer.getCurrentSpan().getSpanName()); - OTelSpan value = captor.getValue(); - assertEquals("span3", value.getSpanName()); - tracer.endSpan(); - assertEquals("noop-span-2", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("noop-span-1", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("span3", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("span2", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("span1", tracer.getCurrentSpan().getSpanName()); - tracer.endSpan(); - assertEquals("root_span", tracer.getCurrentSpan().getSpanName()); - verify(mockOtelSpan, times(4)).end(); - } - - public void testAddAttribute() { - OTelTracer tracer = new OTelTracer(openTelemetry, threadPool, tracerSettings); - - tracer.startSpan("foo", Level.INFO); - tracer.addSpanAttribute("stringKey", "value"); - tracer.addSpanAttribute("longKey", 1L); - tracer.addSpanAttribute("doubleKey", 1.0); - tracer.addSpanAttribute("booleanKey", true); - tracer.endSpan(); - ArgumentCaptor> stringKeyCaptorValues = ArgumentCaptor.forClass(AttributeKey.class); - ArgumentCaptor stringValueCaptorValues = ArgumentCaptor.forClass(String.class); - - // 6 other default string attributes are added - verify(mockOtelSpan, times(1 + 6)).setAttribute(stringKeyCaptorValues.capture(), stringValueCaptorValues.capture()); - verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("longKey", AttributeType.LONG)), eq(1L)); - verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("doubleKey", AttributeType.DOUBLE)), eq(1.0)); - verify(mockOtelSpan).setAttribute(eq(InternalAttributeKeyImpl.create("booleanKey", AttributeType.BOOLEAN)), eq(true)); - - assertTrue(stringValueCaptorValues.getAllValues().contains("value")); - } - - public void testAddEvent() { - ArgumentCaptor stringCaptorValues = ArgumentCaptor.forClass(String.class); - - OTelTracer tracer = new OTelTracer(openTelemetry, threadPool, tracerSettings); - - tracer.startSpan("foo", Level.INFO); - tracer.addSpanEvent("fooEvent"); - tracer.endSpan(); - - tracer.startSpan("bar", Level.DEBUG); - tracer.addSpanEvent("fooEvent"); - tracer.endSpan(); - - verify(mockOtelSpan, times(1)).addEvent(stringCaptorValues.capture()); - assertEquals("fooEvent", stringCaptorValues.getValue()); - } - - private void setupMock() { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); - tracerSettings = new TracerSettings(settings, clusterSettings); - openTelemetry = mock(OpenTelemetry.class); - Tracer mockTracer = mock(Tracer.class); - when(openTelemetry.getTracer(any(String.class))).thenReturn(mockTracer); - captor = ArgumentCaptor.forClass(OTelSpan.class); - mockSpanBuilder = mock(SpanBuilder.class); - mockOtelSpan = mock(io.opentelemetry.api.trace.Span.class); - SpanContext mockSpanContext = mock(SpanContext.class); - when(mockSpanContext.getSpanId()).thenReturn("span_id"); - when(mockSpanContext.getTraceId()).thenReturn("trace_id"); - when(mockOtelSpan.getSpanContext()).thenReturn(mockSpanContext); - when(mockSpanBuilder.startSpan()).thenReturn(mockOtelSpan); - when(mockSpanBuilder.setParent(any())).thenReturn(mockSpanBuilder); - when(mockTracer.spanBuilder(any(String.class))).thenReturn(mockSpanBuilder); - } - -} diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java index da7bac06b7e2f..a5a031742e5a5 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java +++ b/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.tracing.Tracer.CURRENT_SPAN; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; public class TracerUtilsTests extends OpenSearchTestCase { diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 029ece235abba..52f3c0ced51e2 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -69,7 +69,7 @@ import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_COUNT; import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_SIZE; import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; -import static org.opensearch.tracing.Tracer.CURRENT_SPAN; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; /** * A ThreadContext is a map of string headers and a transient map of keyed objects that are associated with @@ -725,7 +725,7 @@ private ThreadContextStruct copyHeaders(Iterable> head } private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { - TracerManager.getTracerHeaderInjector().injectHeader().accept(this.requestHeaders, this.transientHeaders); + TracerManager.getTracerHeaderInjector().accept(this.requestHeaders, this.transientHeaders); final Map requestHeaders; if (defaultHeaders.isEmpty()) { diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index 3e1f5679bf4db..7b8b356d76de2 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -1016,8 +1016,8 @@ protected Node( if (FeatureFlags.isEnabled(TRACER)) { final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); List tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class); - TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings); - TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector()); + TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); + TracerManager.initTracerManager(tracerSettings, tracerModule.getTelemetrySupplier(), threadPool); resourcesToClose.add(TracerManager::closeTracer); } diff --git a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java index 830a4f6e3a1f1..c344aeadb2874 100644 --- a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java @@ -8,9 +8,7 @@ package org.opensearch.plugins; -import org.opensearch.threadpool.ThreadPool; -import org.opensearch.tracing.Tracer; -import org.opensearch.tracing.TracerHeaderInjector; +import org.opensearch.tracing.Telemetry; import org.opensearch.tracing.TracerSettings; import java.util.Map; @@ -21,7 +19,6 @@ */ public interface TracerPlugin { - Map> getTracers(ThreadPool threadPool, TracerSettings tracerSettings); + Map> getTelemetries(TracerSettings tracerSettings); - Map getHeaderInjectors(); } diff --git a/server/src/main/java/org/opensearch/tracing/AbstractSpan.java b/server/src/main/java/org/opensearch/tracing/AbstractSpan.java new file mode 100644 index 0000000000000..b35d9624ff66a --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/AbstractSpan.java @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +/** + * Base span + */ +public abstract class AbstractSpan implements Span { + + protected final String spanName; + protected final Span parentSpan; + protected final Level level; + + protected AbstractSpan(String spanName, Span parentSpan, Level level) { + this.spanName = spanName; + this.parentSpan = parentSpan; + this.level = level; + } + + @Override + public Span getParentSpan() { + return parentSpan; + } + + @Override + public String getSpanName() { + return spanName; + } + + @Override + public Level getLevel() { + return level; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java new file mode 100644 index 0000000000000..eab93c22af450 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java @@ -0,0 +1,159 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.threadpool.ThreadPool; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Optional; + +/** + * + * The default tracer implementation. This class implements the basic logic for span lifecycle and its state management. + * It also handles tracing context propagation between spans. + * + * It internally uses OpenTelemetry tracer. + * + */ +public class DefaultTracer implements Tracer { + + public static final String CURRENT_SPAN = "current_span"; + + private static final Logger logger = LogManager.getLogger(DefaultTracer.class); + private static final String TRACE_ID = "trace_id"; + private static final String SPAN_ID = "span_id"; + private static final String SPAN_NAME = "span_name"; + private static final String PARENT_SPAN_ID = "p_span_id"; + private static final String THREAD_NAME = "th_name"; + private static final String PARENT_SPAN_NAME = "p_span_name"; + + private final ThreadPool threadPool; + private final TracerSettings tracerSettings; + private final Telemetry telemetry; + private final SpanFactory spanFactory; + + /** + * Creates DefaultTracer instance + * + * @param telemetry Otel global Opentelemetry instance + * @param threadPool Thread pool + * @param tracerSettings tracer related settings + */ + public DefaultTracer(Telemetry telemetry, ThreadPool threadPool, TracerSettings tracerSettings) { + this.telemetry = telemetry; + this.threadPool = threadPool; + this.tracerSettings = tracerSettings; + this.spanFactory = new SpanFactory(tracerSettings, telemetry); + } + + @Override + public void startSpan(String spanName, Level level) { + Span span = createSpan(spanName, getCurrentSpan(), level); + setCurrentSpanInContext(span); + addDefaultAttributes(span); + } + + @Override + public void endSpan() { + Span currentSpan = getCurrentSpan(); + if (currentSpan != null) { + currentSpan.endSpan(); + setCurrentSpanInContext(currentSpan.getParentSpan()); + } + } + + @Override + public void addSpanAttribute(String key, String value) { + Span currentSpan = getCurrentSpan(); + currentSpan.addAttribute(key, value); + } + + @Override + public void addSpanAttribute(String key, long value) { + Span currentSpan = getCurrentSpan(); + currentSpan.addAttribute(key, value); + } + + @Override + public void addSpanAttribute(String key, double value) { + Span currentSpan = getCurrentSpan(); + currentSpan.addAttribute(key, value); + } + + @Override + public void addSpanAttribute(String key, boolean value) { + Span currentSpan = getCurrentSpan(); + currentSpan.addAttribute(key, value); + } + + @Override + public void addSpanEvent(String event) { + Span currentSpan = getCurrentSpan(); + currentSpan.addEvent(event); + } + + @Override + public void close() { + try { + ((Closeable) telemetry).close(); + } catch (IOException e) { + logger.warn("Error while closing tracer", e); + } + } + + @Override + public Span getCurrentSpan() { + Optional optionalSpanFromContext = spanFromThreadContext(); + return optionalSpanFromContext.orElse(spanFromHeader()); + } + + private Span spanFromHeader() { + return telemetry.extractSpanFromHeader(threadPool.getThreadContext().getHeaders()); + } + + private Optional spanFromThreadContext() { + ThreadContext threadContext = threadPool.getThreadContext(); + SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); + + return (spanHolder == null) ? Optional.empty() : Optional.ofNullable(spanHolder.getSpan()); + } + + private Span createSpan(String spanName, Span parentSpan, Level level) { + return spanFactory.createSpan(spanName, parentSpan, level); + } + + private void setCurrentSpanInContext(Span span) { + if (span == null) { + return; + } + ThreadContext threadContext = threadPool.getThreadContext(); + SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); + if (spanHolder == null) { + threadContext.putTransient(CURRENT_SPAN, new SpanHolder(span)); + } else { + spanHolder.setSpan(span); + } + } + + private void addDefaultAttributes(Span span) { + span.addAttribute(SPAN_ID, span.getSpanId()); + span.addAttribute(TRACE_ID, span.getTraceId()); + span.addAttribute(SPAN_NAME, span.getSpanName()); + span.addAttribute(THREAD_NAME, Thread.currentThread().getName()); + if (span.getParentSpan() != null) { + span.addAttribute(PARENT_SPAN_ID, span.getParentSpan().getSpanId()); + span.addAttribute(PARENT_SPAN_NAME, span.getParentSpan().getSpanName()); + } + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/Span.java b/server/src/main/java/org/opensearch/tracing/Span.java index bf0ff1d43225b..91c9dfa69ae6b 100644 --- a/server/src/main/java/org/opensearch/tracing/Span.java +++ b/server/src/main/java/org/opensearch/tracing/Span.java @@ -15,6 +15,8 @@ */ public interface Span { + void endSpan(); + /** * Returns span's parent span */ @@ -30,4 +32,18 @@ public interface Span { */ Level getLevel(); + void addAttribute(String key, String value); + + void addAttribute(String key, Long value); + + void addAttribute(String key, Double value); + + void addAttribute(String key, Boolean value); + + void addEvent(String event); + + String getTraceId(); + + String getSpanId(); + } diff --git a/server/src/main/java/org/opensearch/tracing/SpanFactory.java b/server/src/main/java/org/opensearch/tracing/SpanFactory.java new file mode 100644 index 0000000000000..b5b77d18cba10 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/SpanFactory.java @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.tracing.noop.NoopSpan; + +/** + * Factory to create spans based on the configured level + */ +public class SpanFactory { + + private final TracerSettings tracerSettings; + + private final Telemetry telemetry; + + public SpanFactory(TracerSettings tracerSettings, Telemetry telemetry) { + this.tracerSettings = tracerSettings; + this.telemetry = telemetry; + } + + public Span createSpan(String spanName, Span parentSpan, Level level) { + return isLevelEnabled(level) ? createDefaultSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); + } + + private boolean isLevelEnabled(Level level) { + Level configuredLevel = tracerSettings.getTracerLevel(); + return level.isHigherOrEqual(configuredLevel); + } + + private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { + Span telemetrySpan = telemetry.createSpan(spanName, getLastValidSpanInChain(parentSpan), level); + return telemetrySpan; + } + + private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { + return new NoopSpan(spanName, parentSpan, level); + } + + private Span getLastValidSpanInChain(Span parentSpan) { + while (parentSpan instanceof NoopSpan) { + parentSpan = parentSpan.getParentSpan(); + } + return parentSpan; + } +} diff --git a/server/src/main/java/org/opensearch/tracing/Telemetry.java b/server/src/main/java/org/opensearch/tracing/Telemetry.java new file mode 100644 index 0000000000000..382c983c185d4 --- /dev/null +++ b/server/src/main/java/org/opensearch/tracing/Telemetry.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import java.io.Closeable; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * Interface for Telemetry providers + */ +public interface Telemetry extends Closeable { + + Span createSpan(String spanName, Span parentSpan, Level level); + + Span extractSpanFromHeader(Map header); + + BiConsumer, Map> injectSpanInHeader(); + + void close(); + +} diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/server/src/main/java/org/opensearch/tracing/Tracer.java index 5f1221c987c0b..6d4809367dd05 100644 --- a/server/src/main/java/org/opensearch/tracing/Tracer.java +++ b/server/src/main/java/org/opensearch/tracing/Tracer.java @@ -18,8 +18,6 @@ */ public interface Tracer extends Closeable { - String CURRENT_SPAN = "current_span"; - /** * Starts the {@link Span} with given name and level * diff --git a/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java b/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java deleted file mode 100644 index e0780e11ad3ef..0000000000000 --- a/server/src/main/java/org/opensearch/tracing/TracerHeaderInjector.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import java.util.Map; -import java.util.function.BiConsumer; - -/** - * Interface to add in tracing related context in header - */ -public interface TracerHeaderInjector { - - BiConsumer, Map> injectHeader(); - -} diff --git a/server/src/main/java/org/opensearch/tracing/TracerManager.java b/server/src/main/java/org/opensearch/tracing/TracerManager.java index a8726c5112656..1e0a17e2e8212 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/tracing/TracerManager.java @@ -10,10 +10,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.threadpool.ThreadPool; import org.opensearch.tracing.noop.NoopTracer; -import org.opensearch.tracing.noop.NoopTracerHeaderInjector; import java.io.IOException; +import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.Supplier; /** @@ -30,22 +32,22 @@ public class TracerManager { private volatile Tracer defaultTracer; private final Object mutex = new Object(); private final TracerSettings tracerSettings; - private final Supplier tracerSupplier; - private final TracerHeaderInjector tracerHeaderInjector; + private final Supplier telemetrySupplier; + private final ThreadPool threadPool; /** * Initializes the TracerFactory singleton instance * * @param tracerSettings tracer settings instance - * @param tracerHeaderInjector tracer header injector + * @param threadPool thread pool instance */ public static synchronized void initTracerManager( TracerSettings tracerSettings, - Supplier tracerSupplier, - TracerHeaderInjector tracerHeaderInjector + Supplier tracerSupplier, + ThreadPool threadPool ) { if (INSTANCE == null) { - INSTANCE = new TracerManager(tracerSettings, tracerSupplier, tracerHeaderInjector); + INSTANCE = new TracerManager(tracerSettings, tracerSupplier, threadPool); } else { logger.warn("Trying to double initialize TracerFactory, skipping"); } @@ -59,8 +61,8 @@ public static Tracer getTracer() { return INSTANCE == null ? NoopTracer.INSTANCE : INSTANCE.tracer(); } - public static TracerHeaderInjector getTracerHeaderInjector() { - return INSTANCE == null ? NoopTracerHeaderInjector.INSTANCE : INSTANCE.tracerHeaderInjector(); + public static BiConsumer, Map> getTracerHeaderInjector() { + return INSTANCE == null ? (x, y) -> {} : INSTANCE.tracerHeaderInjector(); } /** @@ -76,18 +78,18 @@ public static void closeTracer() { } } - public TracerManager(TracerSettings tracerSettings, Supplier tracerSupplier, TracerHeaderInjector tracerHeaderInjector) { + public TracerManager(TracerSettings tracerSettings, Supplier telemetrySupplier, ThreadPool threadPool) { this.tracerSettings = tracerSettings; - this.tracerSupplier = tracerSupplier; - this.tracerHeaderInjector = tracerHeaderInjector; + this.telemetrySupplier = telemetrySupplier; + this.threadPool = threadPool; } private Tracer tracer() { return isTracingDisabled() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); } - private TracerHeaderInjector tracerHeaderInjector() { - return isTracingDisabled() ? NoopTracerHeaderInjector.INSTANCE : tracerHeaderInjector; + private BiConsumer, Map> tracerHeaderInjector() { + return isTracingDisabled() ? (x, y) -> {} : telemetrySupplier.get().injectSpanInHeader(); } private boolean isTracingDisabled() { @@ -99,7 +101,7 @@ private Tracer getOrCreateDefaultTracerInstance() { synchronized (mutex) { if (defaultTracer == null) { logger.info("Creating Otel tracer..."); - defaultTracer = tracerSupplier.get(); + defaultTracer = new DefaultTracer(telemetrySupplier.get(), threadPool, tracerSettings); } } } diff --git a/server/src/main/java/org/opensearch/tracing/TracerModule.java b/server/src/main/java/org/opensearch/tracing/TracerModule.java index 276c3441b9b86..6723039b46df0 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerModule.java +++ b/server/src/main/java/org/opensearch/tracing/TracerModule.java @@ -11,7 +11,6 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.plugins.TracerPlugin; -import org.opensearch.threadpool.ThreadPool; import java.util.HashMap; import java.util.List; @@ -35,36 +34,24 @@ public class TracerModule { public static final Setting TRACER_TYPE_SETTING = Setting.simpleString(TRACER_TYPE_KEY, Setting.Property.NodeScope); private final Settings settings; - private final Map> tracerFactories = new HashMap<>(); - private final Map tracerHeaderInjectors = new HashMap<>(); + private final Map> tracerFactories = new HashMap<>(); - public TracerModule(Settings settings, List tracerPlugins, ThreadPool threadPool, TracerSettings tracerSettings) { + public TracerModule(Settings settings, List tracerPlugins, TracerSettings tracerSettings) { this.settings = settings; for (TracerPlugin tracerPlugin : tracerPlugins) { - Map> tracerFactory = tracerPlugin.getTracers(threadPool, tracerSettings); - for (Map.Entry> entry : tracerFactory.entrySet()) { - registerTracer(entry.getKey(), entry.getValue()); + Map> tracerFactory = tracerPlugin.getTelemetries(tracerSettings); + for (Map.Entry> entry : tracerFactory.entrySet()) { + registerTelemetry(entry.getKey(), entry.getValue()); } - - Map headerInjectors = tracerPlugin.getHeaderInjectors(); - for (Map.Entry entry : headerInjectors.entrySet()) { - registerTracerHeaderInjector(entry.getKey(), entry.getValue()); - } - } } - public Supplier getTracerSupplier() { + public Supplier getTelemetrySupplier() { final String tracerType = getTracerType(); return tracerFactories.get(tracerType); } - public TracerHeaderInjector getTracerHeaderInjector() { - final String tracerType = getTracerType(); - return tracerHeaderInjectors.get(tracerType); - } - private String getTracerType() { final String tracerType = TRACER_DEFAULT_TYPE_SETTING.exists(settings) ? TRACER_DEFAULT_TYPE_SETTING.get(settings) @@ -72,16 +59,10 @@ private String getTracerType() { return tracerType; } - private void registerTracer(String key, Supplier factory) { + private void registerTelemetry(String key, Supplier factory) { if (tracerFactories.putIfAbsent(key, factory) != null) { throw new IllegalArgumentException("tracer for name: " + key + " is already registered"); } } - private void registerTracerHeaderInjector(String key, TracerHeaderInjector tracerHeaderInjector) { - if (tracerHeaderInjectors.putIfAbsent(key, tracerHeaderInjector) != null) { - throw new IllegalArgumentException("tracer injector for name: " + key + " is already registered"); - } - } - } diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java b/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java index 516f07380ca15..12847aca30a32 100644 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java @@ -8,36 +8,62 @@ package org.opensearch.tracing.noop; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.tracing.AbstractSpan; import org.opensearch.tracing.Level; import org.opensearch.tracing.Span; /** * No-op implementation of Span */ -public class NoopSpan implements Span { - private final String spanName; - private final Span parentSpan; - private final Level level; +public class NoopSpan extends AbstractSpan { + + private static final Logger logger = LogManager.getLogger(NoopSpan.class); public NoopSpan(String spanName, Span parentSpan, Level level) { - this.spanName = spanName; - this.parentSpan = parentSpan; - this.level = level; + super(spanName, parentSpan, level); + logger.trace("Starting Noop span name:{}", spanName); + } + + @Override + public void endSpan() { + logger.trace("Ending noop span name:{}", spanName); + } + + @Override + public void addAttribute(String key, String value) { + logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); + } + + @Override + public void addAttribute(String key, Long value) { + logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); + } + + @Override + public void addAttribute(String key, Double value) { + logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); + } + + @Override + public void addAttribute(String key, Boolean value) { + logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); } @Override - public Span getParentSpan() { - return parentSpan; + public void addEvent(String event) { + logger.warn("Adding event {} in no op span, will be ignored", event); } @Override - public Level getLevel() { - return level; + public String getTraceId() { + return null; } @Override - public String getSpanName() { - return spanName; + public String getSpanId() { + return null; } } diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java b/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java deleted file mode 100644 index 0f4a419e0d38d..0000000000000 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopTracerHeaderInjector.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing.noop; - -import org.opensearch.tracing.TracerHeaderInjector; - -import java.util.Map; -import java.util.function.BiConsumer; - -/** - * No-op implementation of TracerHeaderInjector - */ -public class NoopTracerHeaderInjector implements TracerHeaderInjector { - - public static final TracerHeaderInjector INSTANCE = new NoopTracerHeaderInjector(); - - private NoopTracerHeaderInjector() {} - - @Override - public BiConsumer, Map> injectHeader() { - return (x, y) -> {}; - } -} diff --git a/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java b/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java new file mode 100644 index 0000000000000..9d32d88ba1e42 --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java @@ -0,0 +1,54 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.tracing.noop.NoopSpan; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class SpanFactoryTests extends OpenSearchTestCase { + + public void testCreateSpanLevelDisabledReturnsNoopSpan() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.ROOT).build(); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + + SpanFactory spanFactory = new SpanFactory(tracerSettings, null); + + assertTrue(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); + } + + public void testCreateSpanLevelEnabledReturnsDefaultSpan() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + + Telemetry mockTelemetry = mock(Telemetry.class); + when(mockTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(tracerSettings, mockTelemetry); + + assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); + } + + private Set> getClusterSettings() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + return allTracerSettings; + } +} diff --git a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java index 204cdf21d17c2..3acc148b632ca 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java @@ -15,8 +15,8 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.threadpool.ThreadPool; import org.opensearch.tracing.noop.NoopTracer; -import org.opensearch.tracing.noop.NoopTracerHeaderInjector; import java.util.HashSet; import java.util.List; @@ -44,7 +44,7 @@ public void testGetTracerWithUninitializedTracerFactory() { public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, null, null); + TracerManager.initTracerManager(tracerSettings, null, mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof NoopTracer); @@ -53,22 +53,13 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, () -> mock(Tracer.class), null); + TracerManager.initTracerManager(tracerSettings, () -> mock(Telemetry.class), mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); - assertFalse(tracer instanceof NoopTracer); + assertTrue(tracer instanceof DefaultTracer); } - public void testGetTracerWithTracingDisabledReturnsNoopHeaderInjector() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, null, null); - - TracerHeaderInjector tracerHeaderInjector = TracerManager.getTracerHeaderInjector(); - assertTrue(tracerHeaderInjector instanceof NoopTracerHeaderInjector); - } - private Set> getClusterSettings() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); From b1647f1e67ea49f26ccc7c33c69b09e123169870 Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 31 May 2023 12:27:38 +0530 Subject: [PATCH 09/38] Add unit tests Signed-off-by: suranjay --- .../org/opensearch/tracing/DefaultTracer.java | 12 +- .../tracing/DefaultTracerTests.java | 148 ++++++++++++++++++ 2 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java index eab93c22af450..0c0009f2dda8c 100644 --- a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java +++ b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java @@ -30,12 +30,12 @@ public class DefaultTracer implements Tracer { public static final String CURRENT_SPAN = "current_span"; private static final Logger logger = LogManager.getLogger(DefaultTracer.class); - private static final String TRACE_ID = "trace_id"; - private static final String SPAN_ID = "span_id"; - private static final String SPAN_NAME = "span_name"; - private static final String PARENT_SPAN_ID = "p_span_id"; - private static final String THREAD_NAME = "th_name"; - private static final String PARENT_SPAN_NAME = "p_span_name"; + static final String TRACE_ID = "trace_id"; + static final String SPAN_ID = "span_id"; + static final String SPAN_NAME = "span_name"; + static final String PARENT_SPAN_ID = "p_span_id"; + static final String THREAD_NAME = "th_name"; + static final String PARENT_SPAN_NAME = "p_span_name"; private final ThreadPool threadPool; private final TracerSettings tracerSettings; diff --git a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java new file mode 100644 index 0000000000000..694d09e56c402 --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java @@ -0,0 +1,148 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.threadpool.TestThreadPool; +import org.opensearch.threadpool.ThreadPool; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.opensearch.tracing.DefaultTracer.SPAN_ID; +import static org.opensearch.tracing.DefaultTracer.TRACE_ID; +import static org.opensearch.tracing.DefaultTracer.SPAN_NAME; +import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; + +public class DefaultTracerTests extends OpenSearchTestCase { + + private ThreadPool testThreadPool; + private Telemetry mockTelemetry; + private Span mockSpan; + private Span mockParentSpan; + private TracerSettings tracerSettings; + + @Override + public void setUp() throws Exception { + super.setUp(); + testThreadPool = new TestThreadPool(getTestName()); + setupMocks(); + } + + @Override + public void tearDown() throws Exception { + ThreadPool.terminate(testThreadPool, 30, TimeUnit.SECONDS); + super.tearDown(); + } + + public void testCreateSpan() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + + defaultTracer.startSpan("span_name", Level.INFO); + + verify(mockSpan).addAttribute(SPAN_ID, "span_id"); + verify(mockSpan).addAttribute(TRACE_ID, "trace_id"); + verify(mockSpan).addAttribute(SPAN_NAME, "span_name"); + assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); + } + + public void testEndSpan() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.endSpan(); + verify(mockSpan).endSpan(); + assertEquals("parent_span_id", defaultTracer.getCurrentSpan().getSpanId()); + } + + public void testAddSpanAttributeString() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.addSpanAttribute("key", "value"); + + verify(mockSpan).addAttribute("key", "value"); + } + + public void testAddSpanAttributeLong() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.addSpanAttribute("key", 1L); + + verify(mockSpan).addAttribute("key", 1L); + } + + public void testAddSpanAttributeDouble() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.addSpanAttribute("key", 1.0); + + verify(mockSpan).addAttribute("key", 1.0); + } + + public void testAddSpanAttributeBoolean() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.addSpanAttribute("key", true); + + verify(mockSpan).addAttribute("key", true); + } + + public void testAddEvent() { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + defaultTracer.startSpan("span_name", Level.INFO); + + defaultTracer.addSpanEvent("eventName"); + + verify(mockSpan).addEvent("eventName"); + } + + public void testClose() throws IOException { + Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + + defaultTracer.close(); + + verify(mockTelemetry).close(); + } + + private Set> getClusterSettings() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + return allTracerSettings; + } + + private void setupMocks() { + Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + mockTelemetry = mock(Telemetry.class); + mockSpan = mock(Span.class); + mockParentSpan = mock(Span.class); + when(mockSpan.getSpanName()).thenReturn("span_name"); + when(mockSpan.getSpanId()).thenReturn("span_id"); + when(mockSpan.getTraceId()).thenReturn("trace_id"); + when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); + when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); + when(mockParentSpan.getTraceId()).thenReturn("trace_id"); + testThreadPool.getThreadContext().putTransient(CURRENT_SPAN, new SpanHolder(mockParentSpan)); + when(mockTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); + } +} From 881fedd05ec8675bba6b22e648fa184c177ce1c5 Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 31 May 2023 17:52:00 +0530 Subject: [PATCH 10/38] Add unit tests Signed-off-by: suranjay --- .../common/util/concurrent/ThreadContext.java | 7 ++- .../org/opensearch/tracing/DefaultTracer.java | 4 +- .../java/org/opensearch/tracing/Level.java | 16 +++--- .../org/opensearch/tracing/SpanFactory.java | 2 +- .../org/opensearch/tracing/SpanHolder.java | 6 --- .../java/org/opensearch/tracing/Tracer.java | 7 --- .../opensearch/tracing/noop/NoopTracer.java | 6 --- .../tracing/DefaultTracerTests.java | 4 +- .../opensearch/tracing/TracerModuleTests.java | 50 +++++++++++++++++++ 9 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 server/src/test/java/org/opensearch/tracing/TracerModuleTests.java diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 52f3c0ced51e2..1bda2ee0a1bdc 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -157,7 +157,7 @@ public StoredContext stashContext() { if (context.transientHeaders.containsKey(CURRENT_SPAN)) { threadContextStruct = threadContextStruct.putTransient( CURRENT_SPAN, - new SpanHolder((SpanHolder) context.transientHeaders.get(CURRENT_SPAN)) + new SpanHolder(((SpanHolder) context.transientHeaders.get(CURRENT_SPAN)).getSpan()) ); } @@ -258,7 +258,10 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collectio final ThreadContextStruct newContext = threadLocal.get(); if (newContext.transientHeaders.containsKey(CURRENT_SPAN)) { - newContext.transientHeaders.put(CURRENT_SPAN, new SpanHolder((SpanHolder) newContext.transientHeaders.get(CURRENT_SPAN))); + newContext.transientHeaders.put( + CURRENT_SPAN, + new SpanHolder(((SpanHolder) newContext.transientHeaders.get(CURRENT_SPAN)).getSpan()) + ); } return () -> { diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java index 0c0009f2dda8c..be61464ee118b 100644 --- a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java +++ b/server/src/main/java/org/opensearch/tracing/DefaultTracer.java @@ -111,8 +111,8 @@ public void close() { } } - @Override - public Span getCurrentSpan() { + // Visible for testing + Span getCurrentSpan() { Optional optionalSpanFromContext = spanFromThreadContext(); return optionalSpanFromContext.orElse(spanFromHeader()); } diff --git a/server/src/main/java/org/opensearch/tracing/Level.java b/server/src/main/java/org/opensearch/tracing/Level.java index f2a59df04a64b..07ca9a4ff9eeb 100644 --- a/server/src/main/java/org/opensearch/tracing/Level.java +++ b/server/src/main/java/org/opensearch/tracing/Level.java @@ -31,36 +31,36 @@ public enum Level { /** * DISABLED is a special level that can be used to turn off tracing. This level is initialized to Integer.MAX_VALUE. */ - DISABLED(Integer.MAX_VALUE), + DISABLED(Byte.MAX_VALUE), /** * ROOT is a tracing level indicating top level/root spans. */ - ROOT(500), + ROOT((byte) 100), /** * TERSE is a tracing level for critical spans */ - TERSE(400), + TERSE((byte) 80), /** * INFO is a tracing level used of generic spans */ - INFO(300), + INFO((byte) 60), /** * DEBUG is a tracing level used for low level spans */ - DEBUG(200), + DEBUG((byte) 40), /** * TRACE is the lowest level span */ - TRACE(100); + TRACE((byte) 20); - private final int value; + private final byte value; - Level(int value) { + Level(byte value) { this.value = value; } diff --git a/server/src/main/java/org/opensearch/tracing/SpanFactory.java b/server/src/main/java/org/opensearch/tracing/SpanFactory.java index b5b77d18cba10..b77e8d39088b1 100644 --- a/server/src/main/java/org/opensearch/tracing/SpanFactory.java +++ b/server/src/main/java/org/opensearch/tracing/SpanFactory.java @@ -13,7 +13,7 @@ /** * Factory to create spans based on the configured level */ -public class SpanFactory { +public final class SpanFactory { private final TracerSettings tracerSettings; diff --git a/server/src/main/java/org/opensearch/tracing/SpanHolder.java b/server/src/main/java/org/opensearch/tracing/SpanHolder.java index 1166194f10895..5df205974b1da 100644 --- a/server/src/main/java/org/opensearch/tracing/SpanHolder.java +++ b/server/src/main/java/org/opensearch/tracing/SpanHolder.java @@ -17,12 +17,6 @@ public class SpanHolder { private final AtomicReference span = new AtomicReference<>(); - public SpanHolder(SpanHolder spanHolder) { - if (spanHolder != null) { - this.span.set(spanHolder.span.get()); - } - } - public SpanHolder(Span span) { this.span.set(span); } diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/server/src/main/java/org/opensearch/tracing/Tracer.java index 6d4809367dd05..9b858af2ca1a9 100644 --- a/server/src/main/java/org/opensearch/tracing/Tracer.java +++ b/server/src/main/java/org/opensearch/tracing/Tracer.java @@ -32,13 +32,6 @@ public interface Tracer extends Closeable { */ void endSpan(); - /** - * Returns the current active {@link Span} - * - * @return current active span - */ - Span getCurrentSpan(); - /** * Adds string attribute to the current active {@link Span}. * diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java index 59a325462fcfe..c190718cdc6d6 100644 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java +++ b/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java @@ -9,7 +9,6 @@ package org.opensearch.tracing.noop; import org.opensearch.tracing.Level; -import org.opensearch.tracing.Span; import org.opensearch.tracing.Tracer; /** @@ -70,11 +69,6 @@ public void addSpanEvent(String event) { } - @Override - public Span getCurrentSpan() { - return null; - } - @Override public void close() { diff --git a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java index 694d09e56c402..90e72fba34cba 100644 --- a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java +++ b/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java @@ -52,7 +52,7 @@ public void tearDown() throws Exception { } public void testCreateSpan() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); @@ -63,7 +63,7 @@ public void testCreateSpan() { } public void testEndSpan() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.endSpan(); diff --git a/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java b/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java new file mode 100644 index 0000000000000..c85d4c4b7dee9 --- /dev/null +++ b/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tracing; + +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.plugins.TracerPlugin; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opensearch.tracing.TracerModule.TRACER_DEFAULT_TYPE_SETTING; + +public class TracerModuleTests extends OpenSearchTestCase { + + public void testGetTelemetrySupplier() { + Settings settings = Settings.builder().put(TRACER_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); + TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + TracerPlugin tracerPlugin1 = mock(TracerPlugin.class); + TracerPlugin tracerPlugin2 = mock(TracerPlugin.class); + Telemetry telemetry1 = mock(Telemetry.class); + Telemetry telemetry2 = mock(Telemetry.class); + when(tracerPlugin1.getTelemetries(tracerSettings)).thenReturn(Map.of("otel", () -> telemetry1)); + when(tracerPlugin2.getTelemetries(tracerSettings)).thenReturn(Map.of("foo", () -> telemetry2)); + List tracerPlugins = List.of(tracerPlugin1, tracerPlugin2); + + TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); + + assertEquals(telemetry1, tracerModule.getTelemetrySupplier().get()); + } + + private Set> getClusterSettings() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + return allTracerSettings; + } +} From 49a10dee0906fc002bd56ade42dc07bef2bfe229 Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 31 May 2023 18:29:20 +0530 Subject: [PATCH 11/38] dummy commit Signed-off-by: suranjay From 3a23e465004eacd542be95e903aa644c6ed7b79c Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 31 May 2023 19:39:22 +0530 Subject: [PATCH 12/38] Adding instrumentation in search flow Signed-off-by: suranjay --- .../action/search/TransportSearchAction.java | 26 +++++++++++++++++-- .../search/internal/ContextIndexSearcher.java | 9 ++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index fd42089a4a9d5..8c7f60107f7b2 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -88,6 +88,8 @@ import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskId; import org.opensearch.threadpool.ThreadPool; +import org.opensearch.tracing.Level; +import org.opensearch.tracing.TracerManager; import org.opensearch.transport.RemoteClusterAware; import org.opensearch.transport.RemoteClusterService; import org.opensearch.transport.RemoteTransportException; @@ -278,15 +280,35 @@ protected void doExecute(Task task, SearchRequest searchRequest, ActionListener< // cancellation. There may be other top level requests like AsyncSearch which is using SearchRequest internally and has it's own // cancellation mechanism. For such cases, the SearchRequest when created can override the createTask and set the // cancelAfterTimeInterval to NO_TIMEOUT and bypass this mechanism + final ActionListener responseListener; if (task instanceof CancellableTask) { - listener = TimeoutTaskCancellationUtility.wrapWithCancellationListener( + responseListener = TimeoutTaskCancellationUtility.wrapWithCancellationListener( client, (CancellableTask) task, clusterService.getClusterSettings(), listener ); + } else { + responseListener = listener; } - executeRequest(task, searchRequest, this::searchAsyncAction, listener); + TracerManager.getTracer().startSpan("SearchTask_" + task.getId(), Level.TERSE); + executeRequest(task, searchRequest, this::searchAsyncAction, getTracingWrappedListener(responseListener)); + } + + private ActionListener getTracingWrappedListener(final ActionListener listener) { + return new ActionListener() { + @Override + public void onResponse(SearchResponse searchResponse) { + listener.onResponse(searchResponse); + TracerManager.getTracer().endSpan(); + } + + @Override + public void onFailure(Exception e) { + listener.onFailure(e); + TracerManager.getTracer().endSpan(); + } + }; } /** diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index 79734b1e25005..016e29667498c 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -76,6 +76,8 @@ import org.opensearch.search.sort.FieldSortBuilder; import org.opensearch.search.sort.MinAndMax; import org.opensearch.search.sort.SortOrder; +import org.opensearch.tracing.Level; +import org.opensearch.tracing.TracerManager; import java.io.IOException; import java.util.ArrayList; @@ -244,6 +246,7 @@ public void search( DocValueFormat[] formats, TotalHits totalHits ) throws IOException { + TracerManager.getTracer().startSpan("IndexSearcher", Level.TERSE); final List collectors = new ArrayList<>(leaves.size()); for (LeafReaderContext ctx : leaves) { final Collector collector = manager.newCollector(); @@ -260,6 +263,7 @@ public void search( mergedTopDocs = new TopFieldDocs(totalHits, mergedTopDocs.scoreDocs, mergedTopDocs.fields); } result.topDocs(new TopDocsAndMaxScore(mergedTopDocs, Float.NaN), formats); + TracerManager.getTracer().endSpan(); } public void search( @@ -283,6 +287,7 @@ public void search( @Override protected void search(List leaves, Weight weight, Collector collector) throws IOException { + TracerManager.getTracer().startSpan("IndexSearcher", Level.TERSE); if (shouldReverseLeafReaderContexts()) { // reverse the segment search order if this flag is true. // Certain queries can benefit if we reverse the segment read order, @@ -295,6 +300,7 @@ protected void search(List leaves, Weight weight, Collector c searchLeaf(leaves.get(i), weight, collector); } } + TracerManager.getTracer().endSpan(); } /** @@ -304,7 +310,7 @@ protected void search(List leaves, Weight weight, Collector c * the provided ctx. */ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collector) throws IOException { - + TracerManager.getTracer().startSpan("IndexSearcher-Leaf", Level.DEBUG); // Check if at all we need to call this leaf for collecting results. if (canMatch(ctx) == false) { return; @@ -351,6 +357,7 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto } } } + TracerManager.getTracer().endSpan(); } private Weight wrapWeight(Weight weight) { From 4a6ded3146f36a35632305a54199d9364dfa0fde Mon Sep 17 00:00:00 2001 From: suranjay Date: Fri, 16 Jun 2023 01:05:41 +0530 Subject: [PATCH 13/38] Revert "Adding instrumentation in search flow" This reverts commit 3a23e465004eacd542be95e903aa644c6ed7b79c. Signed-off-by: suranjay --- .../action/search/TransportSearchAction.java | 26 ++----------------- .../search/internal/ContextIndexSearcher.java | 9 +------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index 8c7f60107f7b2..fd42089a4a9d5 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -88,8 +88,6 @@ import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskId; import org.opensearch.threadpool.ThreadPool; -import org.opensearch.tracing.Level; -import org.opensearch.tracing.TracerManager; import org.opensearch.transport.RemoteClusterAware; import org.opensearch.transport.RemoteClusterService; import org.opensearch.transport.RemoteTransportException; @@ -280,35 +278,15 @@ protected void doExecute(Task task, SearchRequest searchRequest, ActionListener< // cancellation. There may be other top level requests like AsyncSearch which is using SearchRequest internally and has it's own // cancellation mechanism. For such cases, the SearchRequest when created can override the createTask and set the // cancelAfterTimeInterval to NO_TIMEOUT and bypass this mechanism - final ActionListener responseListener; if (task instanceof CancellableTask) { - responseListener = TimeoutTaskCancellationUtility.wrapWithCancellationListener( + listener = TimeoutTaskCancellationUtility.wrapWithCancellationListener( client, (CancellableTask) task, clusterService.getClusterSettings(), listener ); - } else { - responseListener = listener; } - TracerManager.getTracer().startSpan("SearchTask_" + task.getId(), Level.TERSE); - executeRequest(task, searchRequest, this::searchAsyncAction, getTracingWrappedListener(responseListener)); - } - - private ActionListener getTracingWrappedListener(final ActionListener listener) { - return new ActionListener() { - @Override - public void onResponse(SearchResponse searchResponse) { - listener.onResponse(searchResponse); - TracerManager.getTracer().endSpan(); - } - - @Override - public void onFailure(Exception e) { - listener.onFailure(e); - TracerManager.getTracer().endSpan(); - } - }; + executeRequest(task, searchRequest, this::searchAsyncAction, listener); } /** diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index 016e29667498c..79734b1e25005 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -76,8 +76,6 @@ import org.opensearch.search.sort.FieldSortBuilder; import org.opensearch.search.sort.MinAndMax; import org.opensearch.search.sort.SortOrder; -import org.opensearch.tracing.Level; -import org.opensearch.tracing.TracerManager; import java.io.IOException; import java.util.ArrayList; @@ -246,7 +244,6 @@ public void search( DocValueFormat[] formats, TotalHits totalHits ) throws IOException { - TracerManager.getTracer().startSpan("IndexSearcher", Level.TERSE); final List collectors = new ArrayList<>(leaves.size()); for (LeafReaderContext ctx : leaves) { final Collector collector = manager.newCollector(); @@ -263,7 +260,6 @@ public void search( mergedTopDocs = new TopFieldDocs(totalHits, mergedTopDocs.scoreDocs, mergedTopDocs.fields); } result.topDocs(new TopDocsAndMaxScore(mergedTopDocs, Float.NaN), formats); - TracerManager.getTracer().endSpan(); } public void search( @@ -287,7 +283,6 @@ public void search( @Override protected void search(List leaves, Weight weight, Collector collector) throws IOException { - TracerManager.getTracer().startSpan("IndexSearcher", Level.TERSE); if (shouldReverseLeafReaderContexts()) { // reverse the segment search order if this flag is true. // Certain queries can benefit if we reverse the segment read order, @@ -300,7 +295,6 @@ protected void search(List leaves, Weight weight, Collector c searchLeaf(leaves.get(i), weight, collector); } } - TracerManager.getTracer().endSpan(); } /** @@ -310,7 +304,7 @@ protected void search(List leaves, Weight weight, Collector c * the provided ctx. */ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collector) throws IOException { - TracerManager.getTracer().startSpan("IndexSearcher-Leaf", Level.DEBUG); + // Check if at all we need to call this leaf for collecting results. if (canMatch(ctx) == false) { return; @@ -357,7 +351,6 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto } } } - TracerManager.getTracer().endSpan(); } private Weight wrapWeight(Weight weight) { From e394149c4bb13b1da9a9f0c9ab849fb2ec3c6e9b Mon Sep 17 00:00:00 2001 From: suranjay Date: Fri, 16 Jun 2023 01:14:59 +0530 Subject: [PATCH 14/38] Extract foundation telemetry classes to libs Signed-off-by: suranjay --- libs/telemetry/build.gradle | 42 +++++++++ .../org/opensearch/telemetry/Telemetry.java | 31 +++++++ .../telemetry/metrics/MetricsTelemetry.java | 16 ++++ .../telemetry/metrics/package-info.java | 12 +++ .../opensearch/telemetry/package-info.java | 12 +++ .../telemetry}/tracing/AbstractSpan.java | 17 +++- .../telemetry}/tracing/DefaultTracer.java | 73 +++++---------- .../opensearch/telemetry}/tracing/Level.java | 2 +- .../opensearch/telemetry}/tracing/Span.java | 42 ++++++++- .../telemetry}/tracing/SpanFactory.java | 32 +++++-- .../opensearch/telemetry}/tracing/Tracer.java | 2 +- .../tracing/TracerContextStorage.java | 30 +++++++ .../tracing/TracingContextPropagator.java | 20 +++-- .../telemetry/tracing/TracingTelemetry.java | 38 ++++++++ .../telemetry/tracing/noop/NoopSpan.java | 58 ++++++++++++ .../telemetry}/tracing/noop/NoopTracer.java | 9 +- .../telemetry}/tracing/noop/package-info.java | 2 +- .../telemetry/tracing/package-info.java | 12 +++ .../org/opensearch}/DefaultTracerTests.java | 44 ++++----- .../build.gradle | 3 +- .../opentelemetry-api-1.26.0.jar.sha1 | 0 .../licenses/opentelemetry-api-LICENSE.txt | 0 .../licenses/opentelemetry-api-NOTICE.txt | 0 ...entelemetry-api-logs-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-api-logs-LICENSE.txt | 0 .../opentelemetry-api-logs-NOTICE.txt | 0 .../opentelemetry-context-1.26.0.jar.sha1 | 0 .../opentelemetry-context-LICENSE.txt | 0 .../licenses/opentelemetry-context-NOTICE.txt | 0 .../opentelemetry-sdk-1.26.0.jar.sha1 | 0 .../licenses/opentelemetry-sdk-LICENSE.txt | 0 .../licenses/opentelemetry-sdk-NOTICE.txt | 0 .../opentelemetry-sdk-common-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-common-LICENSE.txt | 0 .../opentelemetry-sdk-common-NOTICE.txt | 0 ...entelemetry-sdk-logs-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-sdk-logs-LICENSE.txt | 0 .../opentelemetry-sdk-logs-NOTICE.txt | 0 .../opentelemetry-sdk-metrics-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-metrics-LICENSE.txt | 0 .../opentelemetry-sdk-metrics-NOTICE.txt | 0 .../opentelemetry-sdk-trace-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-trace-LICENSE.txt | 0 .../opentelemetry-sdk-trace-NOTICE.txt | 0 ...pentelemetry-semconv-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-semconv-LICENSE.txt | 0 .../licenses/opentelemetry-semconv-NOTICE.txt | 0 .../tracing/OTelResourceProvider.java | 79 ++++++++++++++++ .../telemetry}/tracing/OTelSpan.java | 14 +-- .../tracing/OTelTracerModulePlugin.java | 22 ++++- .../telemetry/tracing/OtelTelemetryImpl.java | 41 +++++++++ .../OtelTracingContextPropagator.java} | 89 ++++++++++--------- .../tracing/OtelTracingTelemetry.java} | 31 ++----- .../tracing/exporter/FileSpanExporter.java | 2 +- .../tracing/exporter/package-info.java | 2 +- .../telemetry}/tracing/package-info.java | 2 +- .../plugin-metadata/plugin-security.policy | 0 .../org/opensearch/tracing/OTelSpanTests.java | 2 + .../tracing/OTelTracerModulePluginTests.java | 14 ++- .../opensearch/tracing/TracerUtilsTests.java | 22 ++--- .../exporter/FileSpanExporterTests.java | 1 + .../tracing/exporter/MockAppender.java | 0 .../tracing/OTelResourceProvider.java | 64 ------------- server/build.gradle | 2 + .../common/settings/ClusterSettings.java | 4 +- .../common/util/concurrent/ThreadContext.java | 10 +-- .../main/java/org/opensearch/node/Node.java | 6 +- .../org/opensearch/plugins/TracerPlugin.java | 6 +- ...hreadContextBasedTracerContextStorage.java | 61 +++++++++++++ .../tracing/TracerManager.java | 11 ++- .../{ => telemetry}/tracing/TracerModule.java | 3 +- .../tracing/TracerSettings.java | 3 +- .../{ => telemetry}/tracing/package-info.java | 2 +- .../org/opensearch/tracing/SpanHolder.java | 31 ------- .../org/opensearch/tracing/noop/NoopSpan.java | 69 -------------- .../org/opensearch/tracing/LevelTests.java | 1 + .../opensearch/tracing/SpanFactoryTests.java | 9 +- .../tracing/TracerManagerTests.java | 5 +- .../opensearch/tracing/TracerModuleTests.java | 33 +++++-- 79 files changed, 750 insertions(+), 388 deletions(-) create mode 100644 libs/telemetry/build.gradle create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/Telemetry.java create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/package-info.java create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/package-info.java rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/AbstractSpan.java (71%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/DefaultTracer.java (59%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/Level.java (98%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/Span.java (51%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/SpanFactory.java (52%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/Tracer.java (97%) create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java rename server/src/main/java/org/opensearch/tracing/Telemetry.java => libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java (52%) create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/noop/NoopTracer.java (87%) rename {server/src/main/java/org/opensearch => libs/telemetry/src/main/java/org/opensearch/telemetry}/tracing/noop/package-info.java (84%) create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/package-info.java rename {server/src/test/java/org/opensearch/tracing => libs/telemetry/src/test/java/org/opensearch}/DefaultTracerTests.java (70%) rename modules/{tracer-otel => telemetry-otel}/build.gradle (94%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-logs-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-api-logs-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-context-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-context-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-context-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-common-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-common-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-logs-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-logs-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-metrics-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-metrics-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-trace-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-sdk-trace-NOTICE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-semconv-LICENSE.txt (100%) rename modules/{tracer-otel => telemetry-otel}/licenses/opentelemetry-semconv-NOTICE.txt (100%) create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java rename modules/{tracer-otel/src/main/java/org/opensearch => telemetry-otel/src/main/java/org/opensearch/telemetry}/tracing/OTelSpan.java (79%) rename modules/{tracer-otel/src/main/java/org/opensearch => telemetry-otel/src/main/java/org/opensearch/telemetry}/tracing/OTelTracerModulePlugin.java (68%) create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java rename modules/{tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java => telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java} (52%) rename modules/{tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java => telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java} (69%) rename modules/{tracer-otel/src/main/java/org/opensearch => telemetry-otel/src/main/java/org/opensearch/telemetry}/tracing/exporter/FileSpanExporter.java (98%) rename modules/{tracer-otel/src/main/java/org/opensearch => telemetry-otel/src/main/java/org/opensearch/telemetry}/tracing/exporter/package-info.java (82%) rename modules/{tracer-otel/src/main/java/org/opensearch => telemetry-otel/src/main/java/org/opensearch/telemetry}/tracing/package-info.java (86%) rename modules/{tracer-otel => telemetry-otel}/src/main/plugin-metadata/plugin-security.policy (100%) rename modules/{tracer-otel => telemetry-otel}/src/test/java/org/opensearch/tracing/OTelSpanTests.java (96%) rename modules/{tracer-otel => telemetry-otel}/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java (77%) rename modules/{tracer-otel => telemetry-otel}/src/test/java/org/opensearch/tracing/TracerUtilsTests.java (70%) rename modules/{tracer-otel => telemetry-otel}/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java (98%) rename modules/{tracer-otel => telemetry-otel}/src/test/java/org/opensearch/tracing/exporter/MockAppender.java (100%) delete mode 100644 modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java create mode 100644 server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java rename server/src/main/java/org/opensearch/{ => telemetry}/tracing/TracerManager.java (85%) rename server/src/main/java/org/opensearch/{ => telemetry}/tracing/TracerModule.java (96%) rename server/src/main/java/org/opensearch/{ => telemetry}/tracing/TracerSettings.java (98%) rename server/src/main/java/org/opensearch/{ => telemetry}/tracing/package-info.java (86%) delete mode 100644 server/src/main/java/org/opensearch/tracing/SpanHolder.java delete mode 100644 server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java diff --git a/libs/telemetry/build.gradle b/libs/telemetry/build.gradle new file mode 100644 index 0000000000000..3e50b5e383d60 --- /dev/null +++ b/libs/telemetry/build.gradle @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +dependencies { + testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" + testImplementation "junit:junit:${versions.junit}" + testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" + testImplementation(project(":test:framework")) { + exclude group: 'org.opensearch', module: 'opensearch-telemetry' + } +} + +tasks.named('forbiddenApisMain').configure { +// replaceSignatureFiles 'jdk-signatures' +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/Telemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/Telemetry.java new file mode 100644 index 0000000000000..6f50699528b6b --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/Telemetry.java @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import org.opensearch.telemetry.metrics.MetricsTelemetry; +import org.opensearch.telemetry.tracing.TracingTelemetry; + +/** + * Interface defining telemetry + */ +public interface Telemetry { + + /** + * Provides tracing telemetry + * @return tracing telemetry instance + */ + TracingTelemetry getTracingTelemetry(); + + /** + * Provides metrics telemetry + * @return metrics telemetry instance + */ + MetricsTelemetry getMetricsTelemetry(); + +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java new file mode 100644 index 0000000000000..c4cf29e09b3cb --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.metrics; + +/** + * Interface for tracing telemetry providers + */ +public interface MetricsTelemetry { + +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/package-info.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/package-info.java new file mode 100644 index 0000000000000..dfe17cc1c11ed --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains metrics related classes + */ +package org.opensearch.telemetry.metrics; diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/package-info.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/package-info.java new file mode 100644 index 0000000000000..ad76f5e308bea --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains telemetry related classes + */ +package org.opensearch.telemetry; diff --git a/server/src/main/java/org/opensearch/tracing/AbstractSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java similarity index 71% rename from server/src/main/java/org/opensearch/tracing/AbstractSpan.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java index b35d9624ff66a..2783c1ee7c374 100644 --- a/server/src/main/java/org/opensearch/tracing/AbstractSpan.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java @@ -6,17 +6,32 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; /** * Base span */ public abstract class AbstractSpan implements Span { + /** + * name of the span + */ protected final String spanName; + /** + * span's parent span + */ protected final Span parentSpan; + /** + * span's level + */ protected final Level level; + /** + * Base constructor + * @param spanName name of the span + * @param parentSpan span's parent span + * @param level span's level + */ protected AbstractSpan(String spanName, Span parentSpan, Level level) { this.spanName = spanName; this.parentSpan = parentSpan; diff --git a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java similarity index 59% rename from server/src/main/java/org/opensearch/tracing/DefaultTracer.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index be61464ee118b..bd5789b503e07 100644 --- a/server/src/main/java/org/opensearch/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -6,30 +6,26 @@ * compatible open source license. */ -package org.opensearch.tracing; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.common.util.concurrent.ThreadContext; -import org.opensearch.threadpool.ThreadPool; +package org.opensearch.telemetry.tracing; import java.io.Closeable; import java.io.IOException; -import java.util.Optional; +import java.util.function.Supplier; /** * * The default tracer implementation. This class implements the basic logic for span lifecycle and its state management. * It also handles tracing context propagation between spans. * - * It internally uses OpenTelemetry tracer. * */ public class DefaultTracer implements Tracer { + /** + * Key for storing current span + */ public static final String CURRENT_SPAN = "current_span"; - private static final Logger logger = LogManager.getLogger(DefaultTracer.class); static final String TRACE_ID = "trace_id"; static final String SPAN_ID = "span_id"; static final String SPAN_NAME = "span_name"; @@ -37,23 +33,27 @@ public class DefaultTracer implements Tracer { static final String THREAD_NAME = "th_name"; static final String PARENT_SPAN_NAME = "p_span_name"; - private final ThreadPool threadPool; - private final TracerSettings tracerSettings; - private final Telemetry telemetry; + private final TracingTelemetry tracingTelemetry; + private final TracerContextStorage tracerContextStorage; + private final Supplier levelSupplier; private final SpanFactory spanFactory; /** * Creates DefaultTracer instance * - * @param telemetry Otel global Opentelemetry instance - * @param threadPool Thread pool - * @param tracerSettings tracer related settings + * @param tracingTelemetry tracing telemetry instance + * @param tracerContextStorage storage used for storing current span context + * @param levelSupplier configured level supplier */ - public DefaultTracer(Telemetry telemetry, ThreadPool threadPool, TracerSettings tracerSettings) { - this.telemetry = telemetry; - this.threadPool = threadPool; - this.tracerSettings = tracerSettings; - this.spanFactory = new SpanFactory(tracerSettings, telemetry); + public DefaultTracer( + TracingTelemetry tracingTelemetry, + TracerContextStorage tracerContextStorage, + Supplier levelSupplier + ) { + this.tracingTelemetry = tracingTelemetry; + this.tracerContextStorage = tracerContextStorage; + this.levelSupplier = levelSupplier; + this.spanFactory = new SpanFactory(levelSupplier, tracingTelemetry); } @Override @@ -103,29 +103,13 @@ public void addSpanEvent(String event) { } @Override - public void close() { - try { - ((Closeable) telemetry).close(); - } catch (IOException e) { - logger.warn("Error while closing tracer", e); - } + public void close() throws IOException { + ((Closeable) tracingTelemetry).close(); } // Visible for testing Span getCurrentSpan() { - Optional optionalSpanFromContext = spanFromThreadContext(); - return optionalSpanFromContext.orElse(spanFromHeader()); - } - - private Span spanFromHeader() { - return telemetry.extractSpanFromHeader(threadPool.getThreadContext().getHeaders()); - } - - private Optional spanFromThreadContext() { - ThreadContext threadContext = threadPool.getThreadContext(); - SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); - - return (spanHolder == null) ? Optional.empty() : Optional.ofNullable(spanHolder.getSpan()); + return tracerContextStorage.get(CURRENT_SPAN); } private Span createSpan(String spanName, Span parentSpan, Level level) { @@ -133,16 +117,7 @@ private Span createSpan(String spanName, Span parentSpan, Level level) { } private void setCurrentSpanInContext(Span span) { - if (span == null) { - return; - } - ThreadContext threadContext = threadPool.getThreadContext(); - SpanHolder spanHolder = threadContext.getTransient(CURRENT_SPAN); - if (spanHolder == null) { - threadContext.putTransient(CURRENT_SPAN, new SpanHolder(span)); - } else { - spanHolder.setSpan(span); - } + tracerContextStorage.put(CURRENT_SPAN, span); } private void addDefaultAttributes(Span span) { diff --git a/server/src/main/java/org/opensearch/tracing/Level.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java similarity index 98% rename from server/src/main/java/org/opensearch/tracing/Level.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java index 07ca9a4ff9eeb..cd725e37b28bd 100644 --- a/server/src/main/java/org/opensearch/tracing/Level.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import java.util.Arrays; diff --git a/server/src/main/java/org/opensearch/tracing/Span.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java similarity index 51% rename from server/src/main/java/org/opensearch/tracing/Span.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java index 91c9dfa69ae6b..6bc60a7dea8a6 100644 --- a/server/src/main/java/org/opensearch/tracing/Span.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; /** * An interface that represents a tracing span. @@ -15,6 +15,9 @@ */ public interface Span { + /** + * Ends the span + */ void endSpan(); /** @@ -32,18 +35,55 @@ public interface Span { */ Level getLevel(); + /** + * Adds string type attribute in the span + * + * @param key of the attribute + * @param value value of the attribute + */ void addAttribute(String key, String value); + /** + * Adds long type attribute in the span + * + * @param key of the attribute + * @param value value of the attribute + */ void addAttribute(String key, Long value); + /** + * Adds double type attribute in the span + * + * @param key of the attribute + * @param value value of the attribute + */ void addAttribute(String key, Double value); + /** + * Adds boolean type attribute in the span + * + * @param key of the attribute + * @param value value of the attribute + */ void addAttribute(String key, Boolean value); + /** + * Adds an event in the span + * + * @param event name of the event + */ void addEvent(String event); + /** + * Returns traceId of the span + * @return span's traceId + */ String getTraceId(); + /** + * Returns spanId of the span + * @return span's spanId + */ String getSpanId(); } diff --git a/server/src/main/java/org/opensearch/tracing/SpanFactory.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java similarity index 52% rename from server/src/main/java/org/opensearch/tracing/SpanFactory.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java index b77e8d39088b1..3557fe6608dcc 100644 --- a/server/src/main/java/org/opensearch/tracing/SpanFactory.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java @@ -6,35 +6,49 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; -import org.opensearch.tracing.noop.NoopSpan; +import org.opensearch.telemetry.tracing.noop.NoopSpan; + +import java.util.function.Supplier; /** * Factory to create spans based on the configured level */ public final class SpanFactory { - private final TracerSettings tracerSettings; + private final TracingTelemetry tracingTelemetry; - private final Telemetry telemetry; + private final Supplier levelSupplier; - public SpanFactory(TracerSettings tracerSettings, Telemetry telemetry) { - this.tracerSettings = tracerSettings; - this.telemetry = telemetry; + /** + * Creates SpanFactor instance with provided level supplier and tracing telemetry + * @param levelSupplier configured level supplier + * @param tracingTelemetry tracing telemetry + */ + public SpanFactory(Supplier levelSupplier, TracingTelemetry tracingTelemetry) { + this.levelSupplier = levelSupplier; + this.tracingTelemetry = tracingTelemetry; } + /** + * Creates span with provided arguments + * @param spanName name of the span + * @param parentSpan span's parent span + * @param level of the span + * @return span instance + */ public Span createSpan(String spanName, Span parentSpan, Level level) { return isLevelEnabled(level) ? createDefaultSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); } private boolean isLevelEnabled(Level level) { - Level configuredLevel = tracerSettings.getTracerLevel(); + Level configuredLevel = levelSupplier.get(); return level.isHigherOrEqual(configuredLevel); } private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { - Span telemetrySpan = telemetry.createSpan(spanName, getLastValidSpanInChain(parentSpan), level); + Span telemetrySpan = tracingTelemetry.createSpan(spanName, getLastValidSpanInChain(parentSpan), level); return telemetrySpan; } diff --git a/server/src/main/java/org/opensearch/tracing/Tracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java similarity index 97% rename from server/src/main/java/org/opensearch/tracing/Tracer.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java index 9b858af2ca1a9..ce552ca865ee4 100644 --- a/server/src/main/java/org/opensearch/tracing/Tracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import java.io.Closeable; diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java new file mode 100644 index 0000000000000..a31f1fa541075 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +/** + * Storage interface used for storing tracing context + * @param key type + * @param value type + */ +public interface TracerContextStorage { + /** + * Fetches value corresponding to key + * @param key of the tracing context + * @return value for key + */ + V get(K key); + + /** + * Puts tracing context value with key + * @param key of the tracing context + * @param value of the tracing context + */ + void put(K key, V value); +} diff --git a/server/src/main/java/org/opensearch/tracing/Telemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java similarity index 52% rename from server/src/main/java/org/opensearch/tracing/Telemetry.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java index 382c983c185d4..13f28764f881a 100644 --- a/server/src/main/java/org/opensearch/tracing/Telemetry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java @@ -6,23 +6,27 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; -import java.io.Closeable; import java.util.Map; import java.util.function.BiConsumer; /** - * Interface for Telemetry providers + * Interface defining the tracing related context propagation */ -public interface Telemetry extends Closeable { - - Span createSpan(String spanName, Span parentSpan, Level level); +public interface TracingContextPropagator { + /** + * Extracts current span from header + * @param header Headers map + * @return current span + */ Span extractSpanFromHeader(Map header); + /** + * Injects current span in header + * @return consumer to add current span in header map + */ BiConsumer, Map> injectSpanInHeader(); - void close(); - } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java new file mode 100644 index 0000000000000..c1f80090172b9 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import java.io.Closeable; + +/** + * Interface for tracing telemetry providers + */ +public interface TracingTelemetry extends Closeable { + + /** + * Creates span with provided arguments + * @param spanName name of the span + * @param parentSpan span's parent span + * @param level span's level + * @return span instance + */ + Span createSpan(String spanName, Span parentSpan, Level level); + + /** + * provides tracing context propagator + * @return tracing context propagator instance + */ + TracingContextPropagator getContextPropagator(); + + /** + * closes the resource + */ + void close(); + +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java new file mode 100644 index 0000000000000..6d0ffc991d447 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java @@ -0,0 +1,58 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing.noop; + +import org.opensearch.telemetry.tracing.Span; +import org.opensearch.telemetry.tracing.AbstractSpan; +import org.opensearch.telemetry.tracing.Level; + +/** + * No-op implementation of Span + */ +public class NoopSpan extends AbstractSpan { + + /** + * Creates a no-op span + * @param spanName span's name + * @param parentSpan span's parent span + * @param level span's level + */ + public NoopSpan(String spanName, Span parentSpan, Level level) { + super(spanName, parentSpan, level); + } + + @Override + public void endSpan() {} + + @Override + public void addAttribute(String key, String value) {} + + @Override + public void addAttribute(String key, Long value) {} + + @Override + public void addAttribute(String key, Double value) {} + + @Override + public void addAttribute(String key, Boolean value) {} + + @Override + public void addEvent(String event) {} + + @Override + public String getTraceId() { + return null; + } + + @Override + public String getSpanId() { + return null; + } + +} diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java similarity index 87% rename from server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java index c190718cdc6d6..960663039ece6 100644 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java @@ -6,16 +6,19 @@ * compatible open source license. */ -package org.opensearch.tracing.noop; +package org.opensearch.telemetry.tracing.noop; -import org.opensearch.tracing.Level; -import org.opensearch.tracing.Tracer; +import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.Tracer; /** * No-op implementation of Tracer */ public class NoopTracer implements Tracer { + /** + * No-op Tracer instance + */ public static final Tracer INSTANCE = new NoopTracer(); private NoopTracer() {} diff --git a/server/src/main/java/org/opensearch/tracing/noop/package-info.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/package-info.java similarity index 84% rename from server/src/main/java/org/opensearch/tracing/noop/package-info.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/package-info.java index 66b557c48ed20..b9d83e7bc7275 100644 --- a/server/src/main/java/org/opensearch/tracing/noop/package-info.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/package-info.java @@ -9,4 +9,4 @@ /** * Contains No-op implementations */ -package org.opensearch.tracing.noop; +package org.opensearch.telemetry.tracing.noop; diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/package-info.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/package-info.java new file mode 100644 index 0000000000000..66898bd58b753 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * Contains tracing related classes + */ +package org.opensearch.telemetry.tracing; diff --git a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java similarity index 70% rename from server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java rename to libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java index 90e72fba34cba..36d760709ed86 100644 --- a/server/src/test/java/org/opensearch/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java @@ -6,12 +6,18 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch; +import org.junit.Assert; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.tracing.DefaultTracer; +import org.opensearch.telemetry.tracing.Span; +import org.opensearch.telemetry.tracing.Tracer; +import org.opensearch.telemetry.tracing.TracerSettings; +import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; @@ -21,19 +27,17 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.opensearch.tracing.DefaultTracer.SPAN_ID; -import static org.opensearch.tracing.DefaultTracer.TRACE_ID; -import static org.opensearch.tracing.DefaultTracer.SPAN_NAME; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.telemetry.tracing.DefaultTracer.SPAN_ID; public class DefaultTracerTests extends OpenSearchTestCase { private ThreadPool testThreadPool; - private Telemetry mockTelemetry; + private TracingTelemetry mockTracingTelemetry; private Span mockSpan; private Span mockParentSpan; private TracerSettings tracerSettings; @@ -52,27 +56,27 @@ public void tearDown() throws Exception { } public void testCreateSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); verify(mockSpan).addAttribute(SPAN_ID, "span_id"); verify(mockSpan).addAttribute(TRACE_ID, "trace_id"); verify(mockSpan).addAttribute(SPAN_NAME, "span_name"); - assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); + Assert.assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); } public void testEndSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.endSpan(); verify(mockSpan).endSpan(); - assertEquals("parent_span_id", defaultTracer.getCurrentSpan().getSpanId()); + Assert.assertEquals("parent_span_id", defaultTracer.getCurrentSpan().getSpanId()); } public void testAddSpanAttributeString() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", "value"); @@ -81,7 +85,7 @@ public void testAddSpanAttributeString() { } public void testAddSpanAttributeLong() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", 1L); @@ -90,7 +94,7 @@ public void testAddSpanAttributeLong() { } public void testAddSpanAttributeDouble() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", 1.0); @@ -99,7 +103,7 @@ public void testAddSpanAttributeDouble() { } public void testAddSpanAttributeBoolean() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", true); @@ -108,7 +112,7 @@ public void testAddSpanAttributeBoolean() { } public void testAddEvent() { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanEvent("eventName"); @@ -117,11 +121,11 @@ public void testAddEvent() { } public void testClose() throws IOException { - Tracer defaultTracer = new DefaultTracer(mockTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); defaultTracer.close(); - verify(mockTelemetry).close(); + verify(mockTracingTelemetry).close(); } private Set> getClusterSettings() { @@ -133,7 +137,7 @@ private Set> getClusterSettings() { private void setupMocks() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - mockTelemetry = mock(Telemetry.class); + mockTracingTelemetry = mock(TracingTelemetry.class); mockSpan = mock(Span.class); mockParentSpan = mock(Span.class); when(mockSpan.getSpanName()).thenReturn("span_name"); @@ -142,7 +146,7 @@ private void setupMocks() { when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); when(mockParentSpan.getTraceId()).thenReturn("trace_id"); - testThreadPool.getThreadContext().putTransient(CURRENT_SPAN, new SpanHolder(mockParentSpan)); - when(mockTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); + testThreadPool.getThreadContext().putTransient(CURRENT_SPAN, new AtomicReference<>(mockParentSpan)); + when(mockTracingTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); } } diff --git a/modules/tracer-otel/build.gradle b/modules/telemetry-otel/build.gradle similarity index 94% rename from modules/tracer-otel/build.gradle rename to modules/telemetry-otel/build.gradle index 2b20b05137760..c6cf7ce075c40 100644 --- a/modules/tracer-otel/build.gradle +++ b/modules/telemetry-otel/build.gradle @@ -13,11 +13,12 @@ import org.opensearch.gradle.info.BuildParams opensearchplugin { description 'Opentelemetry based Tracer implementation.' - classname 'org.opensearch.tracing.OTelTracerModulePlugin' + classname 'org.opensearch.telemetry.tracing.OTelTracerModulePlugin' hasClientJar = true } dependencies { + api project(":libs:opensearch-telemetry") api "io.opentelemetry:opentelemetry-api:${versions.opentelemetry}" api "io.opentelemetry:opentelemetry-context:${versions.opentelemetry}" api "io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}" diff --git a/modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-api-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-api-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-api-logs-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-logs-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-api-logs-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-api-logs-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-context-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-context-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-context-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-context-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-common-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-common-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-common-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-common-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 rename to modules/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 diff --git a/modules/tracer-otel/licenses/opentelemetry-semconv-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-semconv-LICENSE.txt rename to modules/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt diff --git a/modules/tracer-otel/licenses/opentelemetry-semconv-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt similarity index 100% rename from modules/tracer-otel/licenses/opentelemetry-semconv-NOTICE.txt rename to modules/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java new file mode 100644 index 0000000000000..a57ef56de055e --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java @@ -0,0 +1,79 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import org.opensearch.common.SetOnce; +import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; + +import java.util.concurrent.TimeUnit; + +/** + * This class encapsulates all OpenTelemetry related resources + */ +final class OTelResourceProvider { + + private final static SetOnce openTelemetry = new SetOnce<>(); + + static OpenTelemetry get(TracerSettings tracerSettings) { + return get( + tracerSettings, + new FileSpanExporter(), + ContextPropagators.create(W3CTraceContextPropagator.getInstance()), + Sampler.alwaysOn() + ); + } + + static OpenTelemetry get( + TracerSettings tracerSettings, + SpanExporter spanExporter, + ContextPropagators contextPropagators, + Sampler sampler + ) { + if (openTelemetry.get() == null) { + Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); + synchronized (openTelemetry) { + if (openTelemetry.get() == null) { + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(spanProcessor(tracerSettings, spanExporter)) + .setResource(resource) + .setSampler(sampler) + .build(); + + openTelemetry.set( + OpenTelemetrySdk.builder() + .setTracerProvider(sdkTracerProvider) + .setPropagators(contextPropagators) + .buildAndRegisterGlobal() + ); + } + } + } + return openTelemetry.get(); + } + + private static BatchSpanProcessor spanProcessor(TracerSettings tracerSettings, SpanExporter spanExporter) { + return BatchSpanProcessor.builder(spanExporter) + .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) + .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) + .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) + .build(); + } + +} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java similarity index 79% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index 584bbb4ab9cea..9c4cfbd384ad6 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -24,22 +24,10 @@ class OTelSpan extends AbstractSpan { public OTelSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { super(spanName, parentSpan, level); this.otelSpan = span; - logger.trace( - "Starting OtelSpan spanId:{} name:{}: traceId:{}", - otelSpan.getSpanContext().getSpanId(), - spanName, - otelSpan.getSpanContext().getTraceId() - ); } @Override public void endSpan() { - logger.trace( - "Ending span spanId:{} name:{}: traceId:{}", - otelSpan.getSpanContext().getSpanId(), - spanName, - otelSpan.getSpanContext().getTraceId() - ); otelSpan.end(); } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java similarity index 68% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java index d2d9e07ca7207..06b581b6a3095 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelTracerModulePlugin.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java @@ -6,13 +6,15 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; -import io.opentelemetry.api.OpenTelemetry; +import org.opensearch.common.SetOnce; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.TracerPlugin; +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.metrics.MetricsTelemetry; import java.util.Collections; import java.util.Map; @@ -27,6 +29,8 @@ public class OTelTracerModulePlugin extends Plugin implements TracerPlugin { static final String OTEL_TRACER_NAME = "otel"; + private SetOnce telemetry = new SetOnce<>(); + /** * No-args constructor */ @@ -49,7 +53,17 @@ public Map> getTelemetries(TracerSettings tracerSett } private Telemetry getTelemetry(TracerSettings tracerSettings) { - OpenTelemetry openTelemetry = OTelResourceProvider.getOrCreateOpenTelemetryInstance(tracerSettings); - return new OtelTelemetry(openTelemetry); + if (telemetry.get() == null) { + synchronized (telemetry) { + if (telemetry.get() == null) { + telemetry.set( + new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(tracerSettings)), new MetricsTelemetry() { + }) + ); + } + } + } + return telemetry.get(); } + } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java new file mode 100644 index 0000000000000..1d2eb4a176ebf --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java @@ -0,0 +1,41 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.metrics.MetricsTelemetry; + +/** + * Otel implementation of Telemetry + */ +public class OtelTelemetryImpl implements Telemetry { + + private final TracingTelemetry tracingTelemetry; + private final MetricsTelemetry metricsTelemetry; + + /** + * Creates Telemetry instance + * @param tracingTelemetry tracing telemetry + * @param metricsTelemetry metrics telemetry + */ + public OtelTelemetryImpl(TracingTelemetry tracingTelemetry, MetricsTelemetry metricsTelemetry) { + this.tracingTelemetry = tracingTelemetry; + this.metricsTelemetry = metricsTelemetry; + } + + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return metricsTelemetry; + } +} diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java similarity index 52% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index 1a4b406773bcb..a9a2f18daad0c 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/TracerUtils.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -6,25 +6,68 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; +import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapSetter; -import org.opensearch.tracing.noop.NoopSpan; +import org.opensearch.telemetry.tracing.noop.NoopSpan; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; /** - * Contains utils methods for tracing + * Otel implementation of TracingContextPropagator */ -public class TracerUtils { +public class OtelTracingContextPropagator implements TracingContextPropagator { - private TracerUtils() { + private static final String ROOT_SPAN = "root_span"; + private final OpenTelemetry openTelemetry; + + /** + * Creates OtelTracingContextPropagator instance + * @param openTelemetry Otel OpenTelemetry instance + */ + public OtelTracingContextPropagator(OpenTelemetry openTelemetry) { + this.openTelemetry = openTelemetry; + } + + @Override + public Span extractSpanFromHeader(Map header) { + Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), header, TEXT_MAP_GETTER); + if (context != null) { + io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); + return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); + } + return null; + } + + @Override + public BiConsumer, Map> injectSpanInHeader() { + return (requestHeaders, transientHeaders) -> { + if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { + AtomicReference currentSpanRef = (AtomicReference) transientHeaders.get(CURRENT_SPAN); + Span currentSpan = currentSpanRef.get(); + OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); + openTelemetry.getPropagators().getTextMapPropagator().inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); + } + }; + } + + private static Context context(OTelSpan oTelSpan) { + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); + } + + private static OTelSpan getLastValidSpanInChain(Span span) { + while (span instanceof NoopSpan) { + span = span.getParentSpan(); + } + return (OTelSpan) span; } private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { @@ -48,38 +91,4 @@ public String get(Map headers, String key) { } }; - /** - * Adds current active span as tracing context in the header during outbound calls - */ - public static final BiConsumer, Map> addTracerContextToHeader() { - return (requestHeaders, transientHeaders) -> { - if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { - SpanHolder spanHolder = (SpanHolder) transientHeaders.get(CURRENT_SPAN); - Span currentSpan = spanHolder.getSpan(); - OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); - OTelResourceProvider.getContextPropagators() - .getTextMapPropagator() - .inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); - } - }; - } - - /** - * Fetches the tracing context from headers - * @param headers request header map - */ - public static Context extractTracerContextFromHeader(Map headers) { - return OTelResourceProvider.getContextPropagators().getTextMapPropagator().extract(Context.current(), headers, TEXT_MAP_GETTER); - } - - private static Context context(OTelSpan oTelSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); - } - - private static OTelSpan getLastValidSpanInChain(Span span) { - while (span instanceof NoopSpan) { - span = span.getParentSpan(); - } - return (OTelSpan) span; - } } diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java similarity index 69% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java index 0d7072596442d..684aa3c206cc8 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OtelTelemetry.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.context.Context; @@ -15,16 +15,13 @@ import java.io.Closeable; import java.io.IOException; -import java.util.Map; -import java.util.function.BiConsumer; /** * OTel based Telemetry provider */ -public class OtelTelemetry implements Telemetry { +public class OtelTracingTelemetry implements TracingTelemetry { - private static final Logger logger = LogManager.getLogger(OtelTelemetry.class); - private static final String ROOT_SPAN = "root_span"; + private static final Logger logger = LogManager.getLogger(OtelTracingTelemetry.class); private final OpenTelemetry openTelemetry; private final io.opentelemetry.api.trace.Tracer otelTracer; @@ -33,7 +30,7 @@ public class OtelTelemetry implements Telemetry { * Creates OTel based Telemetry * @param openTelemetry OpenTelemetry instance */ - public OtelTelemetry(OpenTelemetry openTelemetry) { + public OtelTracingTelemetry(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; this.otelTracer = openTelemetry.getTracer("os-tracer"); @@ -53,24 +50,14 @@ public Span createSpan(String spanName, Span parentSpan, Level level) { return createOtelSpan(spanName, parentSpan, level); } - private Span createOtelSpan(String spanName, Span parentSpan, Level level) { - io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentSpan); - return new OTelSpan(spanName, otelSpan, parentSpan, level); - } - @Override - public Span extractSpanFromHeader(Map header) { - Context context = TracerUtils.extractTracerContextFromHeader(header); - if (context != null) { - io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); - } - return null; + public TracingContextPropagator getContextPropagator() { + return new OtelTracingContextPropagator(openTelemetry); } - @Override - public BiConsumer, Map> injectSpanInHeader() { - return TracerUtils.addTracerContextToHeader(); + private Span createOtelSpan(String spanName, Span parentSpan, Level level) { + io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentSpan); + return new OTelSpan(spanName, otelSpan, parentSpan, level); } io.opentelemetry.api.trace.Span createOtelSpan(String spanName, Span parentOTelSpan) { diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java similarity index 98% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java index 511f0ec222c77..27f1aa05098de 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/FileSpanExporter.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing.exporter; +package org.opensearch.telemetry.tracing.exporter; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java similarity index 82% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java index b5815891f05f6..6da39e9202ca3 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/exporter/package-info.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java @@ -9,4 +9,4 @@ /** * Contains span exporters */ -package org.opensearch.tracing.exporter; +package org.opensearch.telemetry.tracing.exporter; diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java similarity index 86% rename from modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java index 40572895df90c..4ac1e4c212c81 100644 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/package-info.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java @@ -9,4 +9,4 @@ /** * This package contains classes needed for tracing requests. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; diff --git a/modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy b/modules/telemetry-otel/src/main/plugin-metadata/plugin-security.policy similarity index 100% rename from modules/tracer-otel/src/main/plugin-metadata/plugin-security.policy rename to modules/telemetry-otel/src/main/plugin-metadata/plugin-security.policy diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java similarity index 96% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java index 171a5ae491cb9..08e362e124b79 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java @@ -12,6 +12,8 @@ import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; +import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.OTelSpan; import org.opensearch.test.OpenSearchTestCase; import static org.mockito.Mockito.verify; diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java similarity index 77% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java index df36122eb8c55..6966b6771bce7 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java @@ -13,6 +13,12 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.tracing.OTelTracerModulePlugin; +import org.opensearch.telemetry.tracing.OtelTracingTelemetry; +import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.TracerSettings; +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; @@ -22,7 +28,7 @@ import java.util.Set; import java.util.function.Supplier; -import static org.opensearch.tracing.OTelTracerModulePlugin.OTEL_TRACER_NAME; +import static org.opensearch.telemetry.tracing.OTelTracerModulePlugin.OTEL_TRACER_NAME; public class OTelTracerModulePluginTests extends OpenSearchTestCase { @@ -51,9 +57,9 @@ public void testGetTracers() throws IOException { Map> tracers = new OTelTracerModulePlugin().getTelemetries(tracerSettings); assertEquals(Set.of(OTEL_TRACER_NAME), tracers.keySet()); - Telemetry telemetry = tracers.get(OTEL_TRACER_NAME).get(); - assertTrue(telemetry instanceof OtelTelemetry); - telemetry.close(); + TracingTelemetry tracingTelemetry = tracers.get(OTEL_TRACER_NAME).get().getTracingTelemetry(); + assertTrue(tracingTelemetry instanceof OtelTracingTelemetry); + tracingTelemetry.close(); } diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java similarity index 70% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java index a5a031742e5a5..ea0065a970795 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java @@ -12,16 +12,18 @@ import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; +import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.OTelSpan; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.tracing.noop.NoopSpan; +import org.opensearch.telemetry.tracing.noop.NoopSpan; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; public class TracerUtilsTests extends OpenSearchTestCase { @@ -32,10 +34,10 @@ public void testAddTracerContextToHeader() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); - SpanHolder spanHolder = new SpanHolder(span); + AtomicReference spanHolder = new AtomicReference<>(span); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); + // TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } @@ -44,18 +46,18 @@ public void testAddTracerContextToHeaderWithNoopSpan() { when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); - SpanHolder spanHolder = new SpanHolder(noopSpan); + AtomicReference spanHolder = new AtomicReference(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); + // TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } public void testExtractTracerContextFromHeader() { Map requestHeaders = new HashMap<>(); requestHeaders.put("traceparent", "00-" + TRACE_ID + "-" + SPAN_ID + "-00"); - Context context = TracerUtils.extractTracerContextFromHeader(requestHeaders); - assertEquals(TRACE_ID, Span.fromContext(context).getSpanContext().getTraceId()); - assertEquals(SPAN_ID, Span.fromContext(context).getSpanContext().getSpanId()); + // Context context = TracerUtils.extractTracerContextFromHeader(requestHeaders); + // assertEquals(TRACE_ID, Span.fromContext(context).getSpanContext().getTraceId()); + // assertEquals(SPAN_ID, Span.fromContext(context).getSpanContext().getSpanId()); } } diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java similarity index 98% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java index 6bac3030bceaa..85bf9ec530eaa 100644 --- a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java @@ -20,6 +20,7 @@ import org.junit.BeforeClass; import org.mockito.Mockito; import org.opensearch.common.logging.Loggers; +import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; import org.opensearch.test.OpenSearchTestCase; import java.util.Arrays; diff --git a/modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java b/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java similarity index 100% rename from modules/tracer-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java rename to modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java diff --git a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java b/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java deleted file mode 100644 index 179f323714c12..0000000000000 --- a/modules/tracer-otel/src/main/java/org/opensearch/tracing/OTelResourceProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import org.opensearch.tracing.exporter.FileSpanExporter; - -import java.util.concurrent.TimeUnit; - -/** - * This class encapsulates all OpenTelemetry related resources - */ -final class OTelResourceProvider { - - private static final ContextPropagators contextPropagators; - private static volatile OpenTelemetry OPEN_TELEMETRY; - - static { - contextPropagators = ContextPropagators.create(W3CTraceContextPropagator.getInstance()); - } - - static OpenTelemetry getOrCreateOpenTelemetryInstance(TracerSettings tracerSettings) { - if (OPEN_TELEMETRY == null) { - synchronized (OTelResourceProvider.class) { - if (OPEN_TELEMETRY == null) { - Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor( - BatchSpanProcessor.builder(new FileSpanExporter()) - .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) - .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) - .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) - .build() - ) - .setResource(resource) - .build(); - OPEN_TELEMETRY = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(contextPropagators) - .buildAndRegisterGlobal(); - } - } - } - return OPEN_TELEMETRY; - } - - static ContextPropagators getContextPropagators() { - return contextPropagators; - } -} diff --git a/server/build.gradle b/server/build.gradle index 36b6f465bd80b..6620bc1c62d0c 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -102,6 +102,8 @@ dependencies { api project(':libs:opensearch-secure-sm') api project(':libs:opensearch-x-content') api project(":libs:opensearch-geo") + api project(":libs:opensearch-telemetry") + compileOnly project(':libs:opensearch-plugin-classloader') testRuntimeOnly project(':libs:opensearch-plugin-classloader') diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 9b0f98a8eaaaf..26c5e62ef45b0 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -51,8 +51,8 @@ import org.opensearch.tasks.TaskManager; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.tasks.consumer.TopNSearchTasksLogger; -import org.opensearch.tracing.TracerModule; -import org.opensearch.tracing.TracerSettings; +import org.opensearch.telemetry.tracing.TracerModule; +import org.opensearch.telemetry.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.opensearch.action.admin.indices.close.TransportCloseIndexAction; diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 1bda2ee0a1bdc..185240fbc0183 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -44,8 +44,7 @@ import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; import org.opensearch.http.HttpTransportSettings; -import org.opensearch.tracing.SpanHolder; -import org.opensearch.tracing.TracerManager; +import org.opensearch.telemetry.tracing.TracerManager; import org.opensearch.tasks.Task; import java.io.IOException; @@ -59,6 +58,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; import java.util.function.Function; @@ -69,7 +69,7 @@ import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_COUNT; import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_SIZE; import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; -import static org.opensearch.tracing.DefaultTracer.CURRENT_SPAN; +import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; /** * A ThreadContext is a map of string headers and a transient map of keyed objects that are associated with @@ -157,7 +157,7 @@ public StoredContext stashContext() { if (context.transientHeaders.containsKey(CURRENT_SPAN)) { threadContextStruct = threadContextStruct.putTransient( CURRENT_SPAN, - new SpanHolder(((SpanHolder) context.transientHeaders.get(CURRENT_SPAN)).getSpan()) + new AtomicReference<>(((AtomicReference) context.transientHeaders.get(CURRENT_SPAN)).get()) ); } @@ -260,7 +260,7 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collectio if (newContext.transientHeaders.containsKey(CURRENT_SPAN)) { newContext.transientHeaders.put( CURRENT_SPAN, - new SpanHolder(((SpanHolder) newContext.transientHeaders.get(CURRENT_SPAN)).getSpan()) + new AtomicReference<>(((AtomicReference) newContext.transientHeaders.get(CURRENT_SPAN)).get()) ); } diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index 7b8b356d76de2..12e25e71042c2 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -56,7 +56,7 @@ import org.opensearch.monitor.fs.FsProbe; import org.opensearch.plugins.ExtensionAwarePlugin; import org.opensearch.plugins.SearchPipelinePlugin; -import org.opensearch.tracing.TracerManager; +import org.opensearch.telemetry.tracing.TracerManager; import org.opensearch.search.backpressure.SearchBackpressureService; import org.opensearch.search.backpressure.settings.SearchBackpressureSettings; import org.opensearch.search.pipeline.SearchPipelineService; @@ -64,8 +64,8 @@ import org.opensearch.tasks.consumer.TopNSearchTasksLogger; import org.opensearch.threadpool.RunnableTaskExecutionListener; import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory; -import org.opensearch.tracing.TracerModule; -import org.opensearch.tracing.TracerSettings; +import org.opensearch.telemetry.tracing.TracerModule; +import org.opensearch.telemetry.tracing.TracerSettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.core.Assertions; import org.opensearch.Build; diff --git a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java index c344aeadb2874..f1e78da093b3d 100644 --- a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/TracerPlugin.java @@ -8,14 +8,14 @@ package org.opensearch.plugins; -import org.opensearch.tracing.Telemetry; -import org.opensearch.tracing.TracerSettings; +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.tracing.TracerSettings; import java.util.Map; import java.util.function.Supplier; /** - * Plugin for extending tracing related classes + * Plugin for extending telemetry related classes */ public interface TracerPlugin { diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java new file mode 100644 index 0000000000000..b3bdb26b0d7f4 --- /dev/null +++ b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java @@ -0,0 +1,61 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import org.opensearch.common.util.concurrent.ThreadContext; + +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Core's ThreadContext based TracerContextStorage implementaion + */ +public class ThreadContextBasedTracerContextStorage implements TracerContextStorage { + + private final ThreadContext threadContext; + + private final TracingTelemetry tracingTelemetry; + + public ThreadContextBasedTracerContextStorage(ThreadContext threadContext, TracingTelemetry tracingTelemetry) { + this.threadContext = threadContext; + this.tracingTelemetry = tracingTelemetry; + } + + @Override + public Span get(String key) { + return getCurrentSpan(key); + } + + @Override + public void put(String key, Span span) { + if (span == null) { + return; + } + AtomicReference currentSpanRef = threadContext.getTransient(key); + if (currentSpanRef == null) { + threadContext.putTransient(key, new AtomicReference<>(span)); + } else { + currentSpanRef.set(span); + } + } + + Span getCurrentSpan(String key) { + Optional optionalSpanFromContext = spanFromThreadContext(key); + return optionalSpanFromContext.orElse(spanFromHeader()); + } + + private Optional spanFromThreadContext(String key) { + AtomicReference currentSpanRef = threadContext.getTransient(key); + return (currentSpanRef == null) ? Optional.empty() : Optional.ofNullable(currentSpanRef.get()); + } + + private Span spanFromHeader() { + return tracingTelemetry.getContextPropagator().extractSpanFromHeader(threadContext.getHeaders()); + } +} diff --git a/server/src/main/java/org/opensearch/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java similarity index 85% rename from server/src/main/java/org/opensearch/tracing/TracerManager.java rename to server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index 1e0a17e2e8212..db4c7e80b2917 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -6,12 +6,13 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.tracing.noop.NoopTracer; import org.opensearch.threadpool.ThreadPool; -import org.opensearch.tracing.noop.NoopTracer; import java.io.IOException; import java.util.Map; @@ -89,7 +90,7 @@ private Tracer tracer() { } private BiConsumer, Map> tracerHeaderInjector() { - return isTracingDisabled() ? (x, y) -> {} : telemetrySupplier.get().injectSpanInHeader(); + return isTracingDisabled() ? (x, y) -> {} : telemetrySupplier.get().getTracingTelemetry().getContextPropagator().injectSpanInHeader(); } private boolean isTracingDisabled() { @@ -101,7 +102,9 @@ private Tracer getOrCreateDefaultTracerInstance() { synchronized (mutex) { if (defaultTracer == null) { logger.info("Creating Otel tracer..."); - defaultTracer = new DefaultTracer(telemetrySupplier.get(), threadPool, tracerSettings); + TracingTelemetry tracingTelemetry = telemetrySupplier.get().getTracingTelemetry(); + TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage(threadPool.getThreadContext(), tracingTelemetry); + defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage, () -> tracerSettings.getTracerLevel()); } } } diff --git a/server/src/main/java/org/opensearch/tracing/TracerModule.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java similarity index 96% rename from server/src/main/java/org/opensearch/tracing/TracerModule.java rename to server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java index 6723039b46df0..9cc24eb835c05 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerModule.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java @@ -6,11 +6,12 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.plugins.TracerPlugin; +import org.opensearch.telemetry.Telemetry; import java.util.HashMap; import java.util.List; diff --git a/server/src/main/java/org/opensearch/tracing/TracerSettings.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java similarity index 98% rename from server/src/main/java/org/opensearch/tracing/TracerSettings.java rename to server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java index 5e0c3954d2d1d..238a1b7e2dd43 100644 --- a/server/src/main/java/org/opensearch/tracing/TracerSettings.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; @@ -17,7 +17,6 @@ * Wrapper class to encapsulate tracing related settings */ public class TracerSettings { - // TODO move this public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( "tracer.exporter.batch_size", 512, diff --git a/server/src/main/java/org/opensearch/tracing/package-info.java b/server/src/main/java/org/opensearch/telemetry/tracing/package-info.java similarity index 86% rename from server/src/main/java/org/opensearch/tracing/package-info.java rename to server/src/main/java/org/opensearch/telemetry/tracing/package-info.java index 40572895df90c..4ac1e4c212c81 100644 --- a/server/src/main/java/org/opensearch/tracing/package-info.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/package-info.java @@ -9,4 +9,4 @@ /** * This package contains classes needed for tracing requests. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; diff --git a/server/src/main/java/org/opensearch/tracing/SpanHolder.java b/server/src/main/java/org/opensearch/tracing/SpanHolder.java deleted file mode 100644 index 5df205974b1da..0000000000000 --- a/server/src/main/java/org/opensearch/tracing/SpanHolder.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import java.util.concurrent.atomic.AtomicReference; - -/** - * Mutable wrapper class to store {@link Span}. - */ -public class SpanHolder { - - private final AtomicReference span = new AtomicReference<>(); - - public SpanHolder(Span span) { - this.span.set(span); - } - - public Span getSpan() { - return span.get(); - } - - public void setSpan(Span span) { - this.span.set(span); - } -} diff --git a/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java b/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java deleted file mode 100644 index 12847aca30a32..0000000000000 --- a/server/src/main/java/org/opensearch/tracing/noop/NoopSpan.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing.noop; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.tracing.AbstractSpan; -import org.opensearch.tracing.Level; -import org.opensearch.tracing.Span; - -/** - * No-op implementation of Span - */ -public class NoopSpan extends AbstractSpan { - - private static final Logger logger = LogManager.getLogger(NoopSpan.class); - - public NoopSpan(String spanName, Span parentSpan, Level level) { - super(spanName, parentSpan, level); - logger.trace("Starting Noop span name:{}", spanName); - } - - @Override - public void endSpan() { - logger.trace("Ending noop span name:{}", spanName); - } - - @Override - public void addAttribute(String key, String value) { - logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); - } - - @Override - public void addAttribute(String key, Long value) { - logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); - } - - @Override - public void addAttribute(String key, Double value) { - logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); - } - - @Override - public void addAttribute(String key, Boolean value) { - logger.warn("Adding attribute {}:{} in no op span, will be ignored", key, value); - } - - @Override - public void addEvent(String event) { - logger.warn("Adding event {} in no op span, will be ignored", event); - } - - @Override - public String getTraceId() { - return null; - } - - @Override - public String getSpanId() { - return null; - } - -} diff --git a/server/src/test/java/org/opensearch/tracing/LevelTests.java b/server/src/test/java/org/opensearch/tracing/LevelTests.java index de13d23e85b9c..632247167f0ef 100644 --- a/server/src/test/java/org/opensearch/tracing/LevelTests.java +++ b/server/src/test/java/org/opensearch/tracing/LevelTests.java @@ -8,6 +8,7 @@ package org.opensearch.tracing; +import org.opensearch.telemetry.tracing.Level; import org.opensearch.test.OpenSearchTestCase; public class LevelTests extends OpenSearchTestCase { diff --git a/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java b/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java index 9d32d88ba1e42..0a5e991c0f18a 100644 --- a/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java +++ b/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java @@ -12,8 +12,9 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.tracing.*; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.tracing.noop.NoopSpan; +import org.opensearch.telemetry.tracing.noop.NoopSpan; import java.util.HashSet; import java.util.List; @@ -39,9 +40,9 @@ public void testCreateSpanLevelEnabledReturnsDefaultSpan() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - Telemetry mockTelemetry = mock(Telemetry.class); - when(mockTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(tracerSettings, mockTelemetry); + TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); + when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(tracerSettings, mockTracingTelemetry); assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); } diff --git a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java index 3acc148b632ca..cc9763daef0b6 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java @@ -14,9 +14,10 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.tracing.*; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; -import org.opensearch.tracing.noop.NoopTracer; +import org.opensearch.telemetry.tracing.noop.NoopTracer; import java.util.HashSet; import java.util.List; @@ -53,7 +54,7 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, () -> mock(Telemetry.class), mock(ThreadPool.class)); + TracerManager.initTracerManager(tracerSettings, () -> mock(TracingTelemetry.class), mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof DefaultTracer); diff --git a/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java b/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java index c85d4c4b7dee9..2953866e1f62c 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java +++ b/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java @@ -13,6 +13,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.TracerPlugin; +import org.opensearch.telemetry.tracing.*; import org.opensearch.test.OpenSearchTestCase; import java.util.HashSet; @@ -22,7 +23,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.tracing.TracerModule.TRACER_DEFAULT_TYPE_SETTING; +import static org.opensearch.telemetry.tracing.TracerModule.TRACER_DEFAULT_TYPE_SETTING; public class TracerModuleTests extends OpenSearchTestCase { @@ -31,15 +32,35 @@ public void testGetTelemetrySupplier() { TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); TracerPlugin tracerPlugin1 = mock(TracerPlugin.class); TracerPlugin tracerPlugin2 = mock(TracerPlugin.class); - Telemetry telemetry1 = mock(Telemetry.class); - Telemetry telemetry2 = mock(Telemetry.class); - when(tracerPlugin1.getTelemetries(tracerSettings)).thenReturn(Map.of("otel", () -> telemetry1)); - when(tracerPlugin2.getTelemetries(tracerSettings)).thenReturn(Map.of("foo", () -> telemetry2)); + TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); + TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); + when(tracerPlugin1.getTelemetries(tracerSettings)).thenReturn(Map.of("otel", () -> new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry1; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(tracerPlugin2.getTelemetries(tracerSettings)).thenReturn(Map.of("foo", () -> new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry2; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); List tracerPlugins = List.of(tracerPlugin1, tracerPlugin2); TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); - assertEquals(telemetry1, tracerModule.getTelemetrySupplier().get()); + assertEquals(tracingTelemetry1, tracerModule.getTelemetrySupplier().get()); } private Set> getClusterSettings() { From ec378e3fae0630229e2334b8a21d997318c2fda9 Mon Sep 17 00:00:00 2001 From: suranjay Date: Fri, 16 Jun 2023 16:24:55 +0530 Subject: [PATCH 15/38] Fixed unit tests Signed-off-by: suranjay --- libs/telemetry/build.gradle | 2 +- .../tracing}/DefaultTracerTests.java | 61 +++++++------------ .../telemetry}/tracing/LevelTests.java | 3 +- .../telemetry/tracing/SpanFactoryTests.java | 38 ++++++++++++ .../tracing/OTelSpanTests.java | 4 +- .../tracing/OTelTracerModulePluginTests.java | 7 +-- .../OtelTracingContextPropagatorTests.java} | 31 +++++++--- .../tracing/OtelTracingTelemetryTests.java | 58 ++++++++++++++++++ .../exporter/FileSpanExporterTests.java | 3 +- .../tracing/exporter/MockAppender.java | 2 +- ...hreadContextBasedTracerContextStorage.java | 4 +- .../telemetry/tracing/TracerManager.java | 9 ++- .../tracing/TracerManagerTests.java | 9 ++- .../tracing/TracerModuleTests.java | 7 ++- .../opensearch/tracing/SpanFactoryTests.java | 55 ----------------- 15 files changed, 163 insertions(+), 130 deletions(-) rename libs/telemetry/src/test/java/org/opensearch/{ => telemetry/tracing}/DefaultTracerTests.java (65%) rename {server/src/test/java/org/opensearch => libs/telemetry/src/test/java/org/opensearch/telemetry}/tracing/LevelTests.java (91%) create mode 100644 libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java rename modules/telemetry-otel/src/test/java/org/opensearch/{ => telemetry}/tracing/OTelSpanTests.java (95%) rename modules/telemetry-otel/src/test/java/org/opensearch/{ => telemetry}/tracing/OTelTracerModulePluginTests.java (88%) rename modules/telemetry-otel/src/test/java/org/opensearch/{tracing/TracerUtilsTests.java => telemetry/tracing/OtelTracingContextPropagatorTests.java} (60%) create mode 100644 modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java rename modules/telemetry-otel/src/test/java/org/opensearch/{ => telemetry}/tracing/exporter/FileSpanExporterTests.java (97%) rename modules/telemetry-otel/src/test/java/org/opensearch/{ => telemetry}/tracing/exporter/MockAppender.java (95%) rename server/src/test/java/org/opensearch/{ => telemetry}/tracing/TracerManagerTests.java (88%) rename server/src/test/java/org/opensearch/{ => telemetry}/tracing/TracerModuleTests.java (93%) delete mode 100644 server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java diff --git a/libs/telemetry/build.gradle b/libs/telemetry/build.gradle index 3e50b5e383d60..98585ff80371e 100644 --- a/libs/telemetry/build.gradle +++ b/libs/telemetry/build.gradle @@ -38,5 +38,5 @@ dependencies { } tasks.named('forbiddenApisMain').configure { -// replaceSignatureFiles 'jdk-signatures' + replaceSignatureFiles 'jdk-signatures' } diff --git a/libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java similarity index 65% rename from libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java rename to libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 36d760709ed86..257f37a3fcfc4 100644 --- a/libs/telemetry/src/test/java/org/opensearch/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -6,57 +6,43 @@ * compatible open source license. */ -package org.opensearch; +package org.opensearch.telemetry.tracing; import org.junit.Assert; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.DefaultTracer; -import org.opensearch.telemetry.tracing.Span; -import org.opensearch.telemetry.tracing.Tracer; -import org.opensearch.telemetry.tracing.TracerSettings; -import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.TestThreadPool; -import org.opensearch.threadpool.ThreadPool; import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; import static org.opensearch.telemetry.tracing.DefaultTracer.SPAN_ID; +import static org.opensearch.telemetry.tracing.DefaultTracer.SPAN_NAME; +import static org.opensearch.telemetry.tracing.DefaultTracer.TRACE_ID; public class DefaultTracerTests extends OpenSearchTestCase { - private ThreadPool testThreadPool; private TracingTelemetry mockTracingTelemetry; + private TracerContextStorage mockTracerContextStorage; private Span mockSpan; private Span mockParentSpan; - private TracerSettings tracerSettings; + private Supplier levelSupplier; @Override public void setUp() throws Exception { super.setUp(); - testThreadPool = new TestThreadPool(getTestName()); setupMocks(); } @Override public void tearDown() throws Exception { - ThreadPool.terminate(testThreadPool, 30, TimeUnit.SECONDS); super.tearDown(); } public void testCreateSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); @@ -67,16 +53,17 @@ public void testCreateSpan() { } public void testEndSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); + verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); defaultTracer.endSpan(); verify(mockSpan).endSpan(); - Assert.assertEquals("parent_span_id", defaultTracer.getCurrentSpan().getSpanId()); + verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); } public void testAddSpanAttributeString() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", "value"); @@ -85,7 +72,7 @@ public void testAddSpanAttributeString() { } public void testAddSpanAttributeLong() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", 1L); @@ -94,7 +81,7 @@ public void testAddSpanAttributeLong() { } public void testAddSpanAttributeDouble() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", 1.0); @@ -103,7 +90,7 @@ public void testAddSpanAttributeDouble() { } public void testAddSpanAttributeBoolean() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanAttribute("key", true); @@ -112,7 +99,7 @@ public void testAddSpanAttributeBoolean() { } public void testAddEvent() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); defaultTracer.addSpanEvent("eventName"); @@ -121,32 +108,26 @@ public void testAddEvent() { } public void testClose() throws IOException { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, testThreadPool, tracerSettings); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.close(); verify(mockTracingTelemetry).close(); } - private Set> getClusterSettings() { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); - return allTracerSettings; - } - private void setupMocks() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + levelSupplier = () -> Level.INFO; mockTracingTelemetry = mock(TracingTelemetry.class); mockSpan = mock(Span.class); mockParentSpan = mock(Span.class); + mockTracerContextStorage = mock(TracerContextStorage.class); when(mockSpan.getSpanName()).thenReturn("span_name"); when(mockSpan.getSpanId()).thenReturn("span_id"); when(mockSpan.getTraceId()).thenReturn("trace_id"); when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); when(mockParentSpan.getTraceId()).thenReturn("trace_id"); - testThreadPool.getThreadContext().putTransient(CURRENT_SPAN, new AtomicReference<>(mockParentSpan)); + when(mockTracerContextStorage.get(CURRENT_SPAN)).thenReturn(mockParentSpan, mockSpan); when(mockTracingTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); } } diff --git a/server/src/test/java/org/opensearch/tracing/LevelTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java similarity index 91% rename from server/src/test/java/org/opensearch/tracing/LevelTests.java rename to libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java index 632247167f0ef..8c22e1d723841 100644 --- a/server/src/test/java/org/opensearch/tracing/LevelTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java @@ -6,9 +6,8 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; -import org.opensearch.telemetry.tracing.Level; import org.opensearch.test.OpenSearchTestCase; public class LevelTests extends OpenSearchTestCase { diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java new file mode 100644 index 0000000000000..41b876bdb7837 --- /dev/null +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import org.opensearch.telemetry.tracing.noop.NoopSpan; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.function.Supplier; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class SpanFactoryTests extends OpenSearchTestCase { + + public void testCreateSpanLevelDisabledReturnsNoopSpan() { + Supplier levelSupplier = () -> Level.DISABLED; + SpanFactory spanFactory = new SpanFactory(levelSupplier, null); + + assertTrue(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); + } + + public void testCreateSpanLevelEnabledReturnsDefaultSpan() { + Supplier levelSupplier = () -> Level.INFO; + TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); + when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(levelSupplier, mockTracingTelemetry); + + assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); + } +} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java similarity index 95% rename from modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java index 08e362e124b79..604094d606278 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelSpanTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java @@ -6,14 +6,12 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; -import org.opensearch.telemetry.tracing.Level; -import org.opensearch.telemetry.tracing.OTelSpan; import org.opensearch.test.OpenSearchTestCase; import static org.mockito.Mockito.verify; diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java similarity index 88% rename from modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java index 6966b6771bce7..23e659ddb2493 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/OTelTracerModulePluginTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java @@ -6,19 +6,14 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.opensearch.common.SuppressForbidden; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.OTelTracerModulePlugin; -import org.opensearch.telemetry.tracing.OtelTracingTelemetry; -import org.opensearch.telemetry.tracing.Level; -import org.opensearch.telemetry.tracing.TracerSettings; import org.opensearch.telemetry.Telemetry; -import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java similarity index 60% rename from modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index ea0065a970795..5519d796fe947 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/TracerUtilsTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -6,16 +6,17 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; +import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; -import org.opensearch.telemetry.tracing.Level; -import org.opensearch.telemetry.tracing.OTelSpan; -import org.opensearch.test.OpenSearchTestCase; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.propagation.ContextPropagators; import org.opensearch.telemetry.tracing.noop.NoopSpan; +import org.opensearch.test.OpenSearchTestCase; import java.util.HashMap; import java.util.Map; @@ -25,7 +26,7 @@ import static org.mockito.Mockito.when; import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; -public class TracerUtilsTests extends OpenSearchTestCase { +public class OtelTracingContextPropagatorTests extends OpenSearchTestCase { private static final String TRACE_ID = "4aa59968f31dcbff7807741afa9d7d62"; private static final String SPAN_ID = "bea205cd25756b5e"; @@ -37,7 +38,11 @@ public void testAddTracerContextToHeader() { AtomicReference spanHolder = new AtomicReference<>(span); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - // TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); + TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); + + tracingContextPropagator.injectSpanInHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } @@ -49,15 +54,21 @@ public void testAddTracerContextToHeaderWithNoopSpan() { AtomicReference spanHolder = new AtomicReference(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); - // TracerUtils.addTracerContextToHeader().accept(requestHeaders, transientHeaders); + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); + TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); + tracingContextPropagator.injectSpanInHeader().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } public void testExtractTracerContextFromHeader() { Map requestHeaders = new HashMap<>(); requestHeaders.put("traceparent", "00-" + TRACE_ID + "-" + SPAN_ID + "-00"); - // Context context = TracerUtils.extractTracerContextFromHeader(requestHeaders); - // assertEquals(TRACE_ID, Span.fromContext(context).getSpanContext().getTraceId()); - // assertEquals(SPAN_ID, Span.fromContext(context).getSpanContext().getSpanId()); + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); + TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); + org.opensearch.telemetry.tracing.Span span = tracingContextPropagator.extractSpanFromHeader(requestHeaders); + assertEquals(TRACE_ID, span.getTraceId()); + assertEquals(SPAN_ID, span.getSpanId()); } } diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java new file mode 100644 index 0000000000000..e211a7a1b186b --- /dev/null +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java @@ -0,0 +1,58 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.Tracer; +import org.opensearch.test.OpenSearchTestCase; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OtelTracingTelemetryTests extends OpenSearchTestCase { + + public void testCreateSpanWithoutParent() { + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + Tracer mockTracer = mock(Tracer.class); + when(mockOpenTelemetry.getTracer("os-tracer")).thenReturn(mockTracer); + SpanBuilder mockSpanBuilder = mock(SpanBuilder.class); + when(mockTracer.spanBuilder("span_name")).thenReturn(mockSpanBuilder); + when(mockSpanBuilder.startSpan()).thenReturn(mock(io.opentelemetry.api.trace.Span.class)); + + TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); + Span span = tracingTelemetry.createSpan("span_name", null, Level.INFO); + + verify(mockSpanBuilder, never()).setParent(any()); + assertNull(span.getParentSpan()); + } + + public void testCreateSpanWithParent() { + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + Tracer mockTracer = mock(Tracer.class); + when(mockOpenTelemetry.getTracer("os-tracer")).thenReturn(mockTracer); + SpanBuilder mockSpanBuilder = mock(SpanBuilder.class); + when(mockTracer.spanBuilder("span_name")).thenReturn(mockSpanBuilder); + when(mockSpanBuilder.setParent(any())).thenReturn(mockSpanBuilder); + when(mockSpanBuilder.startSpan()).thenReturn(mock(io.opentelemetry.api.trace.Span.class)); + + Span parentSpan = new OTelSpan("parent_span", mock(io.opentelemetry.api.trace.Span.class), null, Level.INFO); + + TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); + Span span = tracingTelemetry.createSpan("span_name", parentSpan, Level.INFO); + + verify(mockSpanBuilder).setParent(any()); + assertNotNull(span.getParentSpan()); + assertEquals("parent_span", span.getParentSpan().getSpanName()); + } + +} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java similarity index 97% rename from modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java rename to modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java index 85bf9ec530eaa..bfea5a24019ba 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/FileSpanExporterTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing.exporter; +package org.opensearch.telemetry.tracing.exporter; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; @@ -20,7 +20,6 @@ import org.junit.BeforeClass; import org.mockito.Mockito; import org.opensearch.common.logging.Loggers; -import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; import org.opensearch.test.OpenSearchTestCase; import java.util.Arrays; diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java similarity index 95% rename from modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java rename to modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java index 16f7cd88e4236..b96c2074615e1 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/tracing/exporter/MockAppender.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing.exporter; +package org.opensearch.telemetry.tracing.exporter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java index b3bdb26b0d7f4..c0e77d93b770a 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java @@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicReference; /** - * Core's ThreadContext based TracerContextStorage implementaion + * Core's ThreadContext based TracerContextStorage implementation */ public class ThreadContextBasedTracerContextStorage implements TracerContextStorage { @@ -28,7 +28,7 @@ public ThreadContextBasedTracerContextStorage(ThreadContext threadContext, Traci } @Override - public Span get(String key) { + public Span get(String key) { return getCurrentSpan(key); } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index db4c7e80b2917..fa415ac541897 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -90,7 +90,9 @@ private Tracer tracer() { } private BiConsumer, Map> tracerHeaderInjector() { - return isTracingDisabled() ? (x, y) -> {} : telemetrySupplier.get().getTracingTelemetry().getContextPropagator().injectSpanInHeader(); + return isTracingDisabled() + ? (x, y) -> {} + : telemetrySupplier.get().getTracingTelemetry().getContextPropagator().injectSpanInHeader(); } private boolean isTracingDisabled() { @@ -103,7 +105,10 @@ private Tracer getOrCreateDefaultTracerInstance() { if (defaultTracer == null) { logger.info("Creating Otel tracer..."); TracingTelemetry tracingTelemetry = telemetrySupplier.get().getTracingTelemetry(); - TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage(threadPool.getThreadContext(), tracingTelemetry); + TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( + threadPool.getThreadContext(), + tracingTelemetry + ); defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage, () -> tracerSettings.getTracerLevel()); } } diff --git a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java similarity index 88% rename from server/src/test/java/org/opensearch/tracing/TracerManagerTests.java rename to server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java index cc9763daef0b6..7526727a17b52 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.junit.After; import org.junit.Before; @@ -14,7 +14,7 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.*; +import org.opensearch.telemetry.Telemetry; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; import org.opensearch.telemetry.tracing.noop.NoopTracer; @@ -24,6 +24,7 @@ import java.util.Set; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TracerManagerTests extends OpenSearchTestCase { @@ -54,7 +55,9 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, () -> mock(TracingTelemetry.class), mock(ThreadPool.class)); + Telemetry mockTelemetry = mock(Telemetry.class); + when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); + TracerManager.initTracerManager(tracerSettings, () -> mockTelemetry, mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof DefaultTracer); diff --git a/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java similarity index 93% rename from server/src/test/java/org/opensearch/tracing/TracerModuleTests.java rename to server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java index 2953866e1f62c..092abbcd89de5 100644 --- a/server/src/test/java/org/opensearch/tracing/TracerModuleTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java @@ -6,14 +6,15 @@ * compatible open source license. */ -package org.opensearch.tracing; +package org.opensearch.telemetry.tracing; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.TracerPlugin; -import org.opensearch.telemetry.tracing.*; +import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.metrics.MetricsTelemetry; import org.opensearch.test.OpenSearchTestCase; import java.util.HashSet; @@ -60,7 +61,7 @@ public MetricsTelemetry getMetricsTelemetry() { TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); - assertEquals(tracingTelemetry1, tracerModule.getTelemetrySupplier().get()); + assertEquals(tracingTelemetry1, tracerModule.getTelemetrySupplier().get().getTracingTelemetry()); } private Set> getClusterSettings() { diff --git a/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java b/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java deleted file mode 100644 index 0a5e991c0f18a..0000000000000 --- a/server/src/test/java/org/opensearch/tracing/SpanFactoryTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.tracing; - -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.*; -import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.telemetry.tracing.noop.NoopSpan; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SpanFactoryTests extends OpenSearchTestCase { - - public void testCreateSpanLevelDisabledReturnsNoopSpan() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.ROOT).build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - - SpanFactory spanFactory = new SpanFactory(tracerSettings, null); - - assertTrue(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); - } - - public void testCreateSpanLevelEnabledReturnsDefaultSpan() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - - TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); - when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(tracerSettings, mockTracingTelemetry); - - assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); - } - - private Set> getClusterSettings() { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); - return allTracerSettings; - } -} From 3317ae704a499fb4110258859d686928d5580542 Mon Sep 17 00:00:00 2001 From: suranjay Date: Fri, 16 Jun 2023 19:29:11 +0530 Subject: [PATCH 16/38] Fix type cast error Signed-off-by: suranjay --- .../tracing/OtelTracingContextPropagator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index a9a2f18daad0c..2bab0d5736a16 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -51,10 +51,13 @@ public Span extractSpanFromHeader(Map header) { public BiConsumer, Map> injectSpanInHeader() { return (requestHeaders, transientHeaders) -> { if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { - AtomicReference currentSpanRef = (AtomicReference) transientHeaders.get(CURRENT_SPAN); - Span currentSpan = currentSpanRef.get(); - OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); - openTelemetry.getPropagators().getTextMapPropagator().inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); + if (transientHeaders.get(CURRENT_SPAN) instanceof AtomicReference) { + @SuppressWarnings("unchecked") + AtomicReference currentSpanRef = (AtomicReference) transientHeaders.get(CURRENT_SPAN); + Span currentSpan = currentSpanRef.get(); + OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); + openTelemetry.getPropagators().getTextMapPropagator().inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); + } } }; } From 278d4ac80dcb93fa4ffda62bd7aafbc62bb3dbda Mon Sep 17 00:00:00 2001 From: suranjay Date: Fri, 16 Jun 2023 20:06:11 +0530 Subject: [PATCH 17/38] Fix type cast error in tests Signed-off-by: suranjay --- .../org/opensearch/telemetry/tracing/DefaultTracerTests.java | 1 + .../telemetry/tracing/OtelTracingContextPropagatorTests.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 257f37a3fcfc4..0bd88585ea420 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -115,6 +115,7 @@ public void testClose() throws IOException { verify(mockTracingTelemetry).close(); } + @SuppressWarnings("unchecked") private void setupMocks() { levelSupplier = () -> Level.INFO; mockTracingTelemetry = mock(TracingTelemetry.class); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index 5519d796fe947..2ac50d9b77053 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -51,7 +51,7 @@ public void testAddTracerContextToHeaderWithNoopSpan() { when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); - AtomicReference spanHolder = new AtomicReference(noopSpan); + AtomicReference spanHolder = new AtomicReference<>(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); From 117762dbb9f01b6f3dd37933612dd7489f0ac62c Mon Sep 17 00:00:00 2001 From: suranjay Date: Sun, 18 Jun 2023 18:23:54 +0530 Subject: [PATCH 18/38] Address PR comments Signed-off-by: suranjay --- .../telemetry/metrics/MetricsTelemetry.java | 2 +- .../telemetry/tracing/AbstractSpan.java | 6 +++--- .../telemetry/tracing/DefaultTracer.java | 12 ----------- .../opensearch/telemetry/tracing/Level.java | 7 ------- .../telemetry/tracing/DefaultTracerTests.java | 6 ------ .../telemetry/tracing/LevelTests.java | 2 +- .../telemetry/tracing/SpanFactoryTests.java | 2 +- .../telemetry/tracing/OTelSpan.java | 5 ----- .../telemetry/tracing/TracerManager.java | 2 +- .../telemetry/tracing/TracerSettings.java | 21 ++++++++++++++++++- .../telemetry/tracing/TracerManagerTests.java | 2 +- 11 files changed, 28 insertions(+), 39 deletions(-) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java index c4cf29e09b3cb..fa3b7fd192f1a 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java @@ -9,7 +9,7 @@ package org.opensearch.telemetry.metrics; /** - * Interface for tracing telemetry providers + * Interface for metrics telemetry providers */ public interface MetricsTelemetry { diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java index 2783c1ee7c374..8f634b82ec7d1 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java @@ -16,15 +16,15 @@ public abstract class AbstractSpan implements Span { /** * name of the span */ - protected final String spanName; + private final String spanName; /** * span's parent span */ - protected final Span parentSpan; + private final Span parentSpan; /** * span's level */ - protected final Level level; + private final Level level; /** * Base constructor diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index bd5789b503e07..4e2950841553a 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -26,12 +26,7 @@ public class DefaultTracer implements Tracer { */ public static final String CURRENT_SPAN = "current_span"; - static final String TRACE_ID = "trace_id"; - static final String SPAN_ID = "span_id"; - static final String SPAN_NAME = "span_name"; - static final String PARENT_SPAN_ID = "p_span_id"; static final String THREAD_NAME = "th_name"; - static final String PARENT_SPAN_NAME = "p_span_name"; private final TracingTelemetry tracingTelemetry; private final TracerContextStorage tracerContextStorage; @@ -121,14 +116,7 @@ private void setCurrentSpanInContext(Span span) { } private void addDefaultAttributes(Span span) { - span.addAttribute(SPAN_ID, span.getSpanId()); - span.addAttribute(TRACE_ID, span.getTraceId()); - span.addAttribute(SPAN_NAME, span.getSpanName()); span.addAttribute(THREAD_NAME, Thread.currentThread().getName()); - if (span.getParentSpan() != null) { - span.addAttribute(PARENT_SPAN_ID, span.getParentSpan().getSpanId()); - span.addAttribute(PARENT_SPAN_NAME, span.getParentSpan().getSpanName()); - } } } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java index cd725e37b28bd..9d23749c76005 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java @@ -24,15 +24,8 @@ *
  • TRACE(lowest value)
  • * * - * In addition, there is a level DISABLED that can be used to turn off tracing. By default, tracing is disabled. - * */ public enum Level { - /** - * DISABLED is a special level that can be used to turn off tracing. This level is initialized to Integer.MAX_VALUE. - */ - DISABLED(Byte.MAX_VALUE), - /** * ROOT is a tracing level indicating top level/root spans. */ diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 0bd88585ea420..715e0e6d91b27 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -18,9 +18,6 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; -import static org.opensearch.telemetry.tracing.DefaultTracer.SPAN_ID; -import static org.opensearch.telemetry.tracing.DefaultTracer.SPAN_NAME; -import static org.opensearch.telemetry.tracing.DefaultTracer.TRACE_ID; public class DefaultTracerTests extends OpenSearchTestCase { @@ -46,9 +43,6 @@ public void testCreateSpan() { defaultTracer.startSpan("span_name", Level.INFO); - verify(mockSpan).addAttribute(SPAN_ID, "span_id"); - verify(mockSpan).addAttribute(TRACE_ID, "trace_id"); - verify(mockSpan).addAttribute(SPAN_NAME, "span_name"); Assert.assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java index 8c22e1d723841..4bc6e4f06bede 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java @@ -21,7 +21,7 @@ public void testFromStringWithValidStrings() { public void testFromStringWithInValidString() { Exception exception = assertThrows(IllegalArgumentException.class, () -> Level.fromString("randomString")); assertEquals( - "invalid value for tracing level [randomString], must be in [DISABLED, ROOT, TERSE, INFO, DEBUG, TRACE]", + "invalid value for tracing level [randomString], must be in [ROOT, TERSE, INFO, DEBUG, TRACE]", exception.getMessage() ); } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java index 41b876bdb7837..7620aa827b641 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java @@ -21,7 +21,7 @@ public class SpanFactoryTests extends OpenSearchTestCase { public void testCreateSpanLevelDisabledReturnsNoopSpan() { - Supplier levelSupplier = () -> Level.DISABLED; + Supplier levelSupplier = () -> Level.ROOT; SpanFactory spanFactory = new SpanFactory(levelSupplier, null); assertTrue(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index 9c4cfbd384ad6..07afce35a6472 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -8,17 +8,12 @@ package org.opensearch.telemetry.tracing; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - /** * Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span * lifecycle management by delegating calls to it. */ class OTelSpan extends AbstractSpan { - private static final Logger logger = LogManager.getLogger(OTelSpan.class); - private final io.opentelemetry.api.trace.Span otelSpan; public OTelSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index fa415ac541897..e1272f19bb80c 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -96,7 +96,7 @@ private BiConsumer, Map> tracerHeaderInjecto } private boolean isTracingDisabled() { - return Level.DISABLED == tracerSettings.getTracerLevel(); + return tracerSettings.isTracingEnabled(); } private Tracer getOrCreateDefaultTracerInstance() { diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java index 238a1b7e2dd43..329bc3892731a 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java @@ -39,14 +39,23 @@ public class TracerSettings { ); public static final Setting TRACER_LEVEL_SETTING = new Setting<>( "tracer.level", - Level.DISABLED.name(), + Level.ROOT.name(), Level::fromString, Setting.Property.NodeScope, Setting.Property.Dynamic ); + public static final Setting TRACER_ENABLED_SETTING = Setting.boolSetting( + "tracer.enabled", + false, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + private volatile Level tracerLevel; + private volatile boolean tracingEnabled; + private volatile int exporterBatchSize; private volatile int exporterMaxQueueSize; @@ -55,11 +64,13 @@ public class TracerSettings { public TracerSettings(Settings settings, ClusterSettings clusterSettings) { this.tracerLevel = TRACER_LEVEL_SETTING.get(settings); + this.tracingEnabled = TRACER_ENABLED_SETTING.get(settings); this.exporterBatchSize = TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings); this.exporterMaxQueueSize = TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING.get(settings); this.exporterDelay = TRACER_EXPORTER_DELAY_SETTING.get(settings); clusterSettings.addSettingsUpdateConsumer(TRACER_LEVEL_SETTING, this::setTracerLevel); + clusterSettings.addSettingsUpdateConsumer(TRACER_ENABLED_SETTING, this::setTracingEnabled); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_BATCH_SIZE_SETTING, this::setExporterBatchSize); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, this::setExporterMaxQueueSize); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_DELAY_SETTING, this::setExporterDelay); @@ -69,6 +80,10 @@ public void setTracerLevel(Level tracerLevel) { this.tracerLevel = tracerLevel; } + public void setTracingEnabled(boolean tracingEnabled) { + this.tracingEnabled = tracingEnabled; + } + public void setExporterBatchSize(int exporterBatchSize) { this.exporterBatchSize = exporterBatchSize; } @@ -85,6 +100,10 @@ public Level getTracerLevel() { return tracerLevel; } + public boolean isTracingEnabled() { + return tracingEnabled; + } + public int getExporterBatchSize() { return exporterBatchSize; } diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java index 7526727a17b52..c784f8e2fec35 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java @@ -44,7 +44,7 @@ public void testGetTracerWithUninitializedTracerFactory() { } public void testGetTracerWithTracingDisabledReturnsNoopTracer() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.DISABLED).build(); + Settings settings = Settings.builder().put(TracerSettings.TRACER_ENABLED_SETTING.getKey(), false).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); TracerManager.initTracerManager(tracerSettings, null, mock(ThreadPool.class)); From ba4dd16a1c5b7807a324524b5550597dfcc0fee4 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 19 Jun 2023 00:01:44 +0530 Subject: [PATCH 19/38] Return close on span creation Signed-off-by: suranjay --- .../telemetry/tracing/DefaultTracer.java | 3 +- .../opensearch/telemetry/tracing/Scope.java | 26 +++++++++++++++ .../telemetry/tracing/ScopeImpl.java | 33 +++++++++++++++++++ .../opensearch/telemetry/tracing/Tracer.java | 3 +- .../telemetry/tracing/noop/NoopTracer.java | 5 +-- .../telemetry/tracing/DefaultTracerTests.java | 8 +++++ .../common/settings/ClusterSettings.java | 1 + .../telemetry/tracing/TracerManager.java | 2 +- .../telemetry/tracing/TracerManagerTests.java | 2 +- 9 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Scope.java create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/ScopeImpl.java diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index 4e2950841553a..a6092d1b5ce5d 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -52,10 +52,11 @@ public DefaultTracer( } @Override - public void startSpan(String spanName, Level level) { + public Scope startSpan(String spanName, Level level) { Span span = createSpan(spanName, getCurrentSpan(), level); setCurrentSpanInContext(span); addDefaultAttributes(span); + return new ScopeImpl(() -> endSpan()); } @Override diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Scope.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Scope.java new file mode 100644 index 0000000000000..52f4eaf648eea --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Scope.java @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +/** + * An auto-closeable that represents scope of the span. + * It is recommended that you use this class with a try-with-resources block: + */ +public interface Scope extends AutoCloseable { + /** + * No-op Scope implementation + */ + Scope NO_OP = () -> {}; + + /** + * closes the scope + */ + @Override + void close(); +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/ScopeImpl.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/ScopeImpl.java new file mode 100644 index 0000000000000..30a7ac7fa90e7 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/ScopeImpl.java @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +/** + * Executes the runnable on close + */ +public class ScopeImpl implements Scope { + + private Runnable runnableOnClose; + + /** + * Creates Scope instance + * @param runnableOnClose runnable to execute on scope close + */ + public ScopeImpl(Runnable runnableOnClose) { + this.runnableOnClose = runnableOnClose; + } + + /** + * Executes the runnable to end the scope + */ + @Override + public void close() { + runnableOnClose.run(); + } +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java index ce552ca865ee4..6504bf7aef26d 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java @@ -23,8 +23,9 @@ public interface Tracer extends Closeable { * * @param spanName span name * @param level span tracing level + * @return scope of the span, can be used with try-with-resources to close the span */ - void startSpan(String spanName, Level level); + Scope startSpan(String spanName, Level level); /** * Ends the current active {@link Span} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java index 960663039ece6..6ef932af51e3c 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java @@ -9,6 +9,7 @@ package org.opensearch.telemetry.tracing.noop; import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.Scope; import org.opensearch.telemetry.tracing.Tracer; /** @@ -24,8 +25,8 @@ public class NoopTracer implements Tracer { private NoopTracer() {} @Override - public void startSpan(String spanName, Level level) { - + public Scope startSpan(String spanName, Level level) { + return Scope.NO_OP; } @Override diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 715e0e6d91b27..215f83d35fea1 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -56,6 +56,14 @@ public void testEndSpan() { verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); } + public void testEndSpanByClosingScope() { + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); + try (Scope scope = defaultTracer.startSpan("span_name", Level.INFO)) { + verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); + } + verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); + } + public void testAddSpanAttributeString() { Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); defaultTracer.startSpan("span_name", Level.INFO); diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 919424ccda71a..59e0c20721513 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -681,6 +681,7 @@ public void apply(Settings value, Settings current, Settings previous) { List.of(FeatureFlags.TRACER), List.of( TracerSettings.TRACER_LEVEL_SETTING, + TracerSettings.TRACER_ENABLED_SETTING, TracerSettings.TRACER_EXPORTER_DELAY_SETTING, TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index e1272f19bb80c..5e8f50ca7a4c1 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -96,7 +96,7 @@ private BiConsumer, Map> tracerHeaderInjecto } private boolean isTracingDisabled() { - return tracerSettings.isTracingEnabled(); + return !tracerSettings.isTracingEnabled(); } private Tracer getOrCreateDefaultTracerInstance() { diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java index c784f8e2fec35..cbb8da205a868 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java @@ -53,7 +53,7 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { } public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + Settings settings = Settings.builder().put(TracerSettings.TRACER_ENABLED_SETTING.getKey(), true).build(); TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); Telemetry mockTelemetry = mock(Telemetry.class); when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); From aa7ef69eedb369efb4ce86738b0dc2a4b15b56f2 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 19 Jun 2023 15:23:20 +0530 Subject: [PATCH 20/38] Ensure span level is less than parent's level Signed-off-by: suranjay --- .../opensearch/telemetry/tracing/Level.java | 12 +++++++ .../telemetry/tracing/SpanFactory.java | 22 ++++++++----- .../telemetry/tracing/DefaultTracerTests.java | 2 ++ .../telemetry/tracing/SpanFactoryTests.java | 33 +++++++++++++++++++ .../tracing/OtelTracingTelemetry.java | 2 +- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java index 9d23749c76005..ab83d10c7dd00 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java @@ -93,4 +93,16 @@ public boolean isHigherOrEqual(Level level) { return false; } + /** + * Checks if the current level's value is equal or lower than the given level + * @param level to compare + * @return true if the current level's value is equal or lower than given level's value, false otherwise + */ + public boolean isLessOrEqual(Level level) { + if (level != null) { + return this.value <= level.value; + } + return false; + } + } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java index 3557fe6608dcc..de7a0e48105c4 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java @@ -39,16 +39,26 @@ public SpanFactory(Supplier levelSupplier, TracingTelemetry tracingTeleme * @return span instance */ public Span createSpan(String spanName, Span parentSpan, Level level) { - return isLevelEnabled(level) ? createDefaultSpan(spanName, parentSpan, level) : createNoopSpan(spanName, parentSpan, level); + return isLevelValid(level, parentSpan) + ? createDefaultSpan(spanName, parentSpan, level) + : createNoopSpan(spanName, parentSpan, level); } - private boolean isLevelEnabled(Level level) { + private boolean isLevelValid(Level level, Span parentSpan) { Level configuredLevel = levelSupplier.get(); + return isLevelEnabled(level, configuredLevel) && isLevelLowerThanParentSpanLevel(level, parentSpan); + } + + private boolean isLevelLowerThanParentSpanLevel(Level level, Span parentSpan) { + return parentSpan == null || (!(parentSpan instanceof NoopSpan) && level.isLessOrEqual(parentSpan.getLevel())); + } + + private boolean isLevelEnabled(Level level, Level configuredLevel) { return level.isHigherOrEqual(configuredLevel); } private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { - Span telemetrySpan = tracingTelemetry.createSpan(spanName, getLastValidSpanInChain(parentSpan), level); + Span telemetrySpan = tracingTelemetry.createSpan(spanName, parentSpan, level); return telemetrySpan; } @@ -56,10 +66,4 @@ private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { return new NoopSpan(spanName, parentSpan, level); } - private Span getLastValidSpanInChain(Span parentSpan) { - while (parentSpan instanceof NoopSpan) { - parentSpan = parentSpan.getParentSpan(); - } - return parentSpan; - } } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 215f83d35fea1..6581533b9d308 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -127,9 +127,11 @@ private void setupMocks() { when(mockSpan.getSpanName()).thenReturn("span_name"); when(mockSpan.getSpanId()).thenReturn("span_id"); when(mockSpan.getTraceId()).thenReturn("trace_id"); + when(mockSpan.getLevel()).thenReturn(Level.INFO); when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); when(mockParentSpan.getTraceId()).thenReturn("trace_id"); + when(mockParentSpan.getLevel()).thenReturn(Level.INFO); when(mockTracerContextStorage.get(CURRENT_SPAN)).thenReturn(mockParentSpan, mockSpan); when(mockTracingTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java index 7620aa827b641..5527d929f29bf 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java @@ -35,4 +35,37 @@ public void testCreateSpanLevelEnabledReturnsDefaultSpan() { assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); } + + public void testCreateSpanWithSpanLevelLessThanParentSpanLeve() { + Supplier configuredLevelSupplier = () -> Level.INFO; + TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); + Span mockParentSpan = mock(Span.class); + when(mockParentSpan.getLevel()).thenReturn(Level.TERSE); + when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); + + assertFalse(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); + } + + public void testCreateSpanWithSpanLevelMoreThanParentSpanLeve() { + Supplier configuredLevelSupplier = () -> Level.INFO; + TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); + Span mockParentSpan = mock(Span.class); + when(mockParentSpan.getLevel()).thenReturn(Level.DEBUG); + when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); + + assertTrue(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); + } + + public void testCreateSpanWithSpanLevelSameAsParentSpanLeve() { + Supplier configuredLevelSupplier = () -> Level.INFO; + TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); + Span mockParentSpan = mock(Span.class); + when(mockParentSpan.getLevel()).thenReturn(Level.TERSE); + when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); + SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); + + assertFalse(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); + } } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java index 684aa3c206cc8..660f1ac8cde28 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java @@ -61,7 +61,7 @@ private Span createOtelSpan(String spanName, Span parentSpan, Level level) { } io.opentelemetry.api.trace.Span createOtelSpan(String spanName, Span parentOTelSpan) { - return parentOTelSpan == null + return parentOTelSpan == null || !(parentOTelSpan instanceof OTelSpan) ? otelTracer.spanBuilder(spanName).startSpan() : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getOtelSpan())).startSpan(); } From 8d096c237314cd66699f7d8f3f8cbc86b210730a Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 20 Jun 2023 20:45:34 +0530 Subject: [PATCH 21/38] Address PR comments Signed-off-by: suranjay --- .../tracing/TracingContextPropagator.java | 12 +- modules/telemetry-otel/build.gradle | 4 +- .../telemetry/OTelResourceProvider.java | 64 ++++++++++ .../telemetry/OTelTelemetryModulePlugin.java | 61 +++++++++ .../tracing/OTelResourceProvider.java | 79 ------------ .../telemetry/tracing/OTelSpan.java | 6 +- .../tracing/OTelTracerModulePlugin.java | 69 ---------- .../tracing/OtelTracingContextPropagator.java | 10 +- .../OTelTelemetryModulePluginTests.java | 63 ++++++++++ .../tracing/OTelTracerModulePluginTests.java | 61 --------- .../OtelTracingContextPropagatorTests.java | 6 +- .../common/settings/ClusterSettings.java | 20 +-- .../common/settings/FeatureFlagSettings.java | 2 +- .../opensearch/common/util/FeatureFlags.java | 6 +- .../main/java/org/opensearch/node/Node.java | 20 +-- ...TracerPlugin.java => TelemetryPlugin.java} | 11 +- .../opensearch/telemetry/TelemetryModule.java | 68 ++++++++++ ...erSettings.java => TelemetrySettings.java} | 17 +-- ...hreadContextBasedTracerContextStorage.java | 2 +- .../telemetry/tracing/TracerManager.java | 33 +++-- .../telemetry/tracing/TracerModule.java | 69 ---------- .../telemetry/TelemetryModuleTests.java | 118 ++++++++++++++++++ .../telemetry/tracing/TracerManagerTests.java | 15 +-- .../telemetry/tracing/TracerModuleTests.java | 72 ----------- 24 files changed, 456 insertions(+), 432 deletions(-) create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java delete mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java delete mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java create mode 100644 modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java delete mode 100644 modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java rename server/src/main/java/org/opensearch/plugins/{TracerPlugin.java => TelemetryPlugin.java} (60%) create mode 100644 server/src/main/java/org/opensearch/telemetry/TelemetryModule.java rename server/src/main/java/org/opensearch/telemetry/{tracing/TracerSettings.java => TelemetrySettings.java} (89%) delete mode 100644 server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java create mode 100644 server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java delete mode 100644 server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java index 13f28764f881a..b3ce260a8b9ee 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java @@ -17,16 +17,16 @@ public interface TracingContextPropagator { /** - * Extracts current span from header - * @param header Headers map + * Extracts current span from context + * @param props properties * @return current span */ - Span extractSpanFromHeader(Map header); + Span extract(Map props); /** - * Injects current span in header - * @return consumer to add current span in header map + * Injects tracing context in map + * @return consumer to add tracing context in map */ - BiConsumer, Map> injectSpanInHeader(); + BiConsumer, Map> inject(); } diff --git a/modules/telemetry-otel/build.gradle b/modules/telemetry-otel/build.gradle index c6cf7ce075c40..a95f5f17baece 100644 --- a/modules/telemetry-otel/build.gradle +++ b/modules/telemetry-otel/build.gradle @@ -12,8 +12,8 @@ import org.opensearch.gradle.OS import org.opensearch.gradle.info.BuildParams opensearchplugin { - description 'Opentelemetry based Tracer implementation.' - classname 'org.opensearch.telemetry.tracing.OTelTracerModulePlugin' + description 'Opentelemetry based telemetry implementation.' + classname 'org.opensearch.telemetry.OTelTelemetryModulePlugin' hasClientJar = true } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java new file mode 100644 index 0000000000000..17705c6873775 --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; + +import java.util.concurrent.TimeUnit; + +/** + * This class encapsulates all OpenTelemetry related resources + */ +final class OTelResourceProvider { + + static OpenTelemetry get(TelemetrySettings telemetrySettings) { + return get( + telemetrySettings, + new FileSpanExporter(), + ContextPropagators.create(W3CTraceContextPropagator.getInstance()), + Sampler.alwaysOn() + ); + } + + static OpenTelemetry get( + TelemetrySettings telemetrySettings, + SpanExporter spanExporter, + ContextPropagators contextPropagators, + Sampler sampler + ) { + Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(spanProcessor(telemetrySettings, spanExporter)) + .setResource(resource) + .setSampler(sampler) + .build(); + + return OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).setPropagators(contextPropagators).buildAndRegisterGlobal(); + } + + private static BatchSpanProcessor spanProcessor(TelemetrySettings telemetrySettings, SpanExporter spanExporter) { + return BatchSpanProcessor.builder(spanExporter) + .setScheduleDelay(telemetrySettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) + .setMaxExportBatchSize(telemetrySettings.getExporterBatchSize()) + .setMaxQueueSize(telemetrySettings.getExporterMaxQueueSize()) + .build(); + } + +} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java new file mode 100644 index 0000000000000..759df136288ea --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -0,0 +1,61 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.plugins.Plugin; +import org.opensearch.plugins.TelemetryPlugin; +import org.opensearch.telemetry.metrics.MetricsTelemetry; +import org.opensearch.telemetry.tracing.OtelTelemetryImpl; +import org.opensearch.telemetry.tracing.OtelTracingTelemetry; + +import java.util.Optional; + +import static org.opensearch.common.util.FeatureFlags.TELEMETRY; + +/** + * Telemetry plugin based on Otel + */ +public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin { + + static final String OTEL_TRACER_NAME = "otel"; + + /** + * No-args constructor + */ + public OTelTelemetryModulePlugin() {} + + @Override + public Settings additionalSettings() { + if (FeatureFlags.isEnabled(TELEMETRY)) { + return Settings.builder() + // set Otel tracer as default telemetry provider + .put(TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) + .build(); + } + return Settings.EMPTY; + } + + @Override + public Optional getTelemetry(TelemetrySettings telemetrySettings) { + return Optional.of(telemetry(telemetrySettings)); + } + + @Override + public String getName() { + return OTEL_TRACER_NAME; + } + + private Telemetry telemetry(TelemetrySettings telemetrySettings) { + return new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(telemetrySettings)), new MetricsTelemetry() { + }); + } + +} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java deleted file mode 100644 index a57ef56de055e..0000000000000 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; -import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.sdk.trace.samplers.Sampler; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import org.opensearch.common.SetOnce; -import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; - -import java.util.concurrent.TimeUnit; - -/** - * This class encapsulates all OpenTelemetry related resources - */ -final class OTelResourceProvider { - - private final static SetOnce openTelemetry = new SetOnce<>(); - - static OpenTelemetry get(TracerSettings tracerSettings) { - return get( - tracerSettings, - new FileSpanExporter(), - ContextPropagators.create(W3CTraceContextPropagator.getInstance()), - Sampler.alwaysOn() - ); - } - - static OpenTelemetry get( - TracerSettings tracerSettings, - SpanExporter spanExporter, - ContextPropagators contextPropagators, - Sampler sampler - ) { - if (openTelemetry.get() == null) { - Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); - synchronized (openTelemetry) { - if (openTelemetry.get() == null) { - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(spanProcessor(tracerSettings, spanExporter)) - .setResource(resource) - .setSampler(sampler) - .build(); - - openTelemetry.set( - OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(contextPropagators) - .buildAndRegisterGlobal() - ); - } - } - } - return openTelemetry.get(); - } - - private static BatchSpanProcessor spanProcessor(TracerSettings tracerSettings, SpanExporter spanExporter) { - return BatchSpanProcessor.builder(spanExporter) - .setScheduleDelay(tracerSettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) - .setMaxExportBatchSize(tracerSettings.getExporterBatchSize()) - .setMaxQueueSize(tracerSettings.getExporterMaxQueueSize()) - .build(); - } - -} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index 07afce35a6472..a78db1d04b14c 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -8,15 +8,17 @@ package org.opensearch.telemetry.tracing; +import io.opentelemetry.api.trace.Span; + /** * Default implementation of {@link Span} using Otel span. It keeps a reference of OpenTelemetry Span and handles span * lifecycle management by delegating calls to it. */ class OTelSpan extends AbstractSpan { - private final io.opentelemetry.api.trace.Span otelSpan; + private final Span otelSpan; - public OTelSpan(String spanName, io.opentelemetry.api.trace.Span span, Span parentSpan, Level level) { + public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan, Level level) { super(spanName, parentSpan, level); this.otelSpan = span; } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java deleted file mode 100644 index 06b581b6a3095..0000000000000 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracerModulePlugin.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.common.SetOnce; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.plugins.Plugin; -import org.opensearch.plugins.TracerPlugin; -import org.opensearch.telemetry.Telemetry; -import org.opensearch.telemetry.metrics.MetricsTelemetry; - -import java.util.Collections; -import java.util.Map; -import java.util.function.Supplier; - -import static org.opensearch.common.util.FeatureFlags.TRACER; - -/** - * Tracer plugin based on Otel - */ -public class OTelTracerModulePlugin extends Plugin implements TracerPlugin { - - static final String OTEL_TRACER_NAME = "otel"; - - private SetOnce telemetry = new SetOnce<>(); - - /** - * No-args constructor - */ - public OTelTracerModulePlugin() {} - - @Override - public Settings additionalSettings() { - if (FeatureFlags.isEnabled(TRACER)) { - return Settings.builder() - // set Otel tracer as default tracer - .put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) - .build(); - } - return Settings.EMPTY; - } - - @Override - public Map> getTelemetries(TracerSettings tracerSettings) { - return Collections.singletonMap(OTEL_TRACER_NAME, () -> getTelemetry(tracerSettings)); - } - - private Telemetry getTelemetry(TracerSettings tracerSettings) { - if (telemetry.get() == null) { - synchronized (telemetry) { - if (telemetry.get() == null) { - telemetry.set( - new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(tracerSettings)), new MetricsTelemetry() { - }) - ); - } - } - } - return telemetry.get(); - } - -} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index 2bab0d5736a16..3b02566209645 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -25,7 +25,7 @@ */ public class OtelTracingContextPropagator implements TracingContextPropagator { - private static final String ROOT_SPAN = "root_span"; + private static final String PROPAGATED_SPAN = "propagated_span"; private final OpenTelemetry openTelemetry; @@ -38,17 +38,17 @@ public OtelTracingContextPropagator(OpenTelemetry openTelemetry) { } @Override - public Span extractSpanFromHeader(Map header) { - Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), header, TEXT_MAP_GETTER); + public Span extract(Map props) { + Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), props, TEXT_MAP_GETTER); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OTelSpan(ROOT_SPAN, span, null, Level.ROOT); + return new OTelSpan(PROPAGATED_SPAN, span, null, Level.ROOT); } return null; } @Override - public BiConsumer, Map> injectSpanInHeader() { + public BiConsumer, Map> inject() { return (requestHeaders, transientHeaders) -> { if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { if (transientHeaders.get(CURRENT_SPAN) instanceof AtomicReference) { diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java new file mode 100644 index 0000000000000..0dbc70a0f97b6 --- /dev/null +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -0,0 +1,63 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import org.opensearch.common.SuppressForbidden; +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.tracing.Level; +import org.opensearch.telemetry.tracing.OtelTracingTelemetry; +import org.opensearch.telemetry.tracing.TracingTelemetry; +import org.opensearch.test.OpenSearchTestCase; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Optional; + +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.OTEL_TRACER_NAME; + +public class OTelTelemetryModulePluginTests extends OpenSearchTestCase { + + @SuppressForbidden(reason = "manipulates system properties for testing") + public void testAdditionalSettingWithTracingFeatureDisabled() { + System.setProperty("opensearch.experimental.feature.telemetry.enabled", "false"); + Settings settings = new OTelTelemetryModulePlugin().additionalSettings(); + + assertTrue(settings.isEmpty()); + } + + @SuppressForbidden(reason = "manipulates system properties for testing") + public void testAdditionalSettingWithTracingFeatureEnabled() { + System.setProperty("opensearch.experimental.feature.telemetry.enabled", "true"); + Settings settings = new OTelTelemetryModulePlugin().additionalSettings(); + + assertFalse(settings.isEmpty()); + } + + public void testGetTelemetry() throws IOException { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); + Settings settings = Settings.builder().put(TelemetrySettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterSettings); + OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(); + Optional tracer = oTelTracerModulePlugin.getTelemetry(telemetrySettings); + + assertEquals(OTEL_TRACER_NAME, oTelTracerModulePlugin.getName()); + TracingTelemetry tracingTelemetry = tracer.get().getTracingTelemetry(); + assertTrue(tracingTelemetry instanceof OtelTracingTelemetry); + tracingTelemetry.close(); + + } + +} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java deleted file mode 100644 index 23e659ddb2493..0000000000000 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracerModulePluginTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.common.SuppressForbidden; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.Telemetry; -import org.opensearch.test.OpenSearchTestCase; - -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Supplier; - -import static org.opensearch.telemetry.tracing.OTelTracerModulePlugin.OTEL_TRACER_NAME; - -public class OTelTracerModulePluginTests extends OpenSearchTestCase { - - @SuppressForbidden(reason = "manipulates system properties for testing") - public void testAdditionalSettingWithTracingFeatureDisabled() { - System.setProperty("opensearch.experimental.feature.tracer.enabled", "false"); - Settings settings = new OTelTracerModulePlugin().additionalSettings(); - - assertTrue(settings.isEmpty()); - } - - @SuppressForbidden(reason = "manipulates system properties for testing") - public void testAdditionalSettingWithTracingFeatureEnabled() { - System.setProperty("opensearch.experimental.feature.tracer.enabled", "true"); - Settings settings = new OTelTracerModulePlugin().additionalSettings(); - - assertFalse(settings.isEmpty()); - } - - public void testGetTracers() throws IOException { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); - Settings settings = Settings.builder().put(TracerSettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); - ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); - TracerSettings tracerSettings = new TracerSettings(settings, clusterSettings); - Map> tracers = new OTelTracerModulePlugin().getTelemetries(tracerSettings); - - assertEquals(Set.of(OTEL_TRACER_NAME), tracers.keySet()); - TracingTelemetry tracingTelemetry = tracers.get(OTEL_TRACER_NAME).get().getTracingTelemetry(); - assertTrue(tracingTelemetry instanceof OtelTracingTelemetry); - tracingTelemetry.close(); - - } - -} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index 2ac50d9b77053..1b209ce5558ca 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -42,7 +42,7 @@ public void testAddTracerContextToHeader() { when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); - tracingContextPropagator.injectSpanInHeader().accept(requestHeaders, transientHeaders); + tracingContextPropagator.inject().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } @@ -57,7 +57,7 @@ public void testAddTracerContextToHeaderWithNoopSpan() { OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); - tracingContextPropagator.injectSpanInHeader().accept(requestHeaders, transientHeaders); + tracingContextPropagator.inject().accept(requestHeaders, transientHeaders); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } @@ -67,7 +67,7 @@ public void testExtractTracerContextFromHeader() { OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); - org.opensearch.telemetry.tracing.Span span = tracingContextPropagator.extractSpanFromHeader(requestHeaders); + org.opensearch.telemetry.tracing.Span span = tracingContextPropagator.extract(requestHeaders); assertEquals(TRACE_ID, span.getTraceId()); assertEquals(SPAN_ID, span.getSpanId()); } diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 59e0c20721513..246d663bcd2f9 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -52,8 +52,8 @@ import org.opensearch.tasks.TaskManager; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.tasks.consumer.TopNSearchTasksLogger; -import org.opensearch.telemetry.tracing.TracerModule; -import org.opensearch.telemetry.tracing.TracerSettings; +import org.opensearch.telemetry.TelemetryModule; +import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.opensearch.action.admin.indices.close.TransportCloseIndexAction; @@ -678,15 +678,15 @@ public void apply(Settings value, Settings current, Settings previous) { ), List.of(FeatureFlags.CONCURRENT_SEGMENT_SEARCH), List.of(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING), - List.of(FeatureFlags.TRACER), + List.of(FeatureFlags.TELEMETRY), List.of( - TracerSettings.TRACER_LEVEL_SETTING, - TracerSettings.TRACER_ENABLED_SETTING, - TracerSettings.TRACER_EXPORTER_DELAY_SETTING, - TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, - TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, - TracerModule.TRACER_TYPE_SETTING, - TracerModule.TRACER_DEFAULT_TYPE_SETTING + TelemetrySettings.TRACER_LEVEL_SETTING, + TelemetrySettings.TRACER_ENABLED_SETTING, + TelemetrySettings.TRACER_EXPORTER_DELAY_SETTING, + TelemetrySettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, + TelemetrySettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, + TelemetryModule.TELEMETRY_TYPE_SETTING, + TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING ) ); } diff --git a/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java b/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java index 61b0cfb7dab88..dae66c79c63ec 100644 --- a/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/FeatureFlagSettings.java @@ -40,7 +40,7 @@ protected FeatureFlagSettings( FeatureFlags.IDENTITY_SETTING, FeatureFlags.SEARCH_PIPELINE_SETTING, FeatureFlags.CONCURRENT_SEGMENT_SEARCH_SETTING, - FeatureFlags.TRACER_SETTING + FeatureFlags.TELEMETRY_SETTING ) ) ); diff --git a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java index ee1e4dbe19759..2b4dab616d00f 100644 --- a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java +++ b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java @@ -64,9 +64,9 @@ public class FeatureFlags { public static final String CONCURRENT_SEGMENT_SEARCH = "opensearch.experimental.feature.concurrent_segment_search.enabled"; /** - * Gates the functionality of tracing framework. + * Gates the functionality of telemetry framework. */ - public static final String TRACER = "opensearch.experimental.feature.tracer.enabled"; + public static final String TELEMETRY = "opensearch.experimental.feature.telemetry.enabled"; /** * Should store the settings from opensearch.yml. @@ -110,7 +110,7 @@ public static boolean isEnabled(String featureFlagName) { public static final Setting IDENTITY_SETTING = Setting.boolSetting(IDENTITY, false, Property.NodeScope); - public static final Setting TRACER_SETTING = Setting.boolSetting(TRACER, false, Property.NodeScope); + public static final Setting TELEMETRY_SETTING = Setting.boolSetting(TELEMETRY, false, Property.NodeScope); public static final Setting CONCURRENT_SEGMENT_SEARCH_SETTING = Setting.boolSetting( CONCURRENT_SEGMENT_SEARCH, diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index a594bad7f75e2..c03dcb3df1cc8 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -66,8 +66,8 @@ import org.opensearch.tasks.consumer.TopNSearchTasksLogger; import org.opensearch.threadpool.RunnableTaskExecutionListener; import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory; -import org.opensearch.telemetry.tracing.TracerModule; -import org.opensearch.telemetry.tracing.TracerSettings; +import org.opensearch.telemetry.TelemetryModule; +import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.core.Assertions; import org.opensearch.Build; @@ -197,7 +197,7 @@ import org.opensearch.plugins.ScriptPlugin; import org.opensearch.plugins.SearchPlugin; import org.opensearch.plugins.SystemIndexPlugin; -import org.opensearch.plugins.TracerPlugin; +import org.opensearch.plugins.TelemetryPlugin; import org.opensearch.repositories.RepositoriesModule; import org.opensearch.repositories.RepositoriesService; import org.opensearch.rest.RestController; @@ -258,7 +258,7 @@ import static java.util.stream.Collectors.toList; import static org.opensearch.common.util.FeatureFlags.SEARCH_PIPELINE; -import static org.opensearch.common.util.FeatureFlags.TRACER; +import static org.opensearch.common.util.FeatureFlags.TELEMETRY; import static org.opensearch.env.NodeEnvironment.collectFileCacheDataPath; import static org.opensearch.index.ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY; @@ -1025,11 +1025,11 @@ protected Node( searchModule.getIndexSearcherExecutor(threadPool) ); - if (FeatureFlags.isEnabled(TRACER)) { - final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings()); - List tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class); - TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); - TracerManager.initTracerManager(tracerSettings, tracerModule.getTelemetrySupplier(), threadPool); + if (FeatureFlags.isEnabled(TELEMETRY)) { + final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings()); + List telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class); + TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + TracerManager.initTracerManager(telemetrySettings, telemetryModule.getTelemetry(), threadPool); resourcesToClose.add(TracerManager::closeTracer); } @@ -1494,7 +1494,7 @@ public synchronized void close() throws IOException { toClose.add(() -> stopWatch.stop().start("node_environment")); toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(stopWatch::stop); - if (FeatureFlags.isEnabled(TRACER)) { + if (FeatureFlags.isEnabled(TELEMETRY)) { toClose.add(TracerManager::closeTracer); } diff --git a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java similarity index 60% rename from server/src/main/java/org/opensearch/plugins/TracerPlugin.java rename to server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java index f1e78da093b3d..66033df394d9f 100644 --- a/server/src/main/java/org/opensearch/plugins/TracerPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java @@ -9,16 +9,17 @@ package org.opensearch.plugins; import org.opensearch.telemetry.Telemetry; -import org.opensearch.telemetry.tracing.TracerSettings; +import org.opensearch.telemetry.TelemetrySettings; -import java.util.Map; -import java.util.function.Supplier; +import java.util.Optional; /** * Plugin for extending telemetry related classes */ -public interface TracerPlugin { +public interface TelemetryPlugin { - Map> getTelemetries(TracerSettings tracerSettings); + Optional getTelemetry(TelemetrySettings telemetrySettings); + + String getName(); } diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java new file mode 100644 index 0000000000000..23b52fd2ad2f0 --- /dev/null +++ b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java @@ -0,0 +1,68 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.plugins.TelemetryPlugin; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A module for loading classes for telemetry + * + * @opensearch.internal + */ +public class TelemetryModule { + + private static final String TELEMETRY_TYPE_DEFAULT = "telemetry.type.default"; + private static final String TELEMETRY_TYPE = "telemetry.type"; + + public static final Setting TELEMETRY_DEFAULT_TYPE_SETTING = Setting.simpleString( + TELEMETRY_TYPE_DEFAULT, + Setting.Property.NodeScope + ); + public static final Setting TELEMETRY_TYPE_SETTING = Setting.simpleString(TELEMETRY_TYPE, Setting.Property.NodeScope); + + private final Settings settings; + private final Map telemetryFactories = new HashMap<>(); + + public TelemetryModule(Settings settings, List telemetryPlugins, TelemetrySettings telemetrySettings) { + this.settings = settings; + + for (TelemetryPlugin telemetryPlugin : telemetryPlugins) { + Optional telemetry = telemetryPlugin.getTelemetry(telemetrySettings); + if (telemetry.isPresent()) { + registerTelemetry(telemetryPlugin.getName(), telemetry.get()); + } + } + } + + public Telemetry getTelemetry() { + final String telemetryType = getTelemetryType(); + return telemetryFactories.get(telemetryType); + } + + private String getTelemetryType() { + final String telemetryType = TELEMETRY_TYPE_SETTING.exists(settings) + ? TELEMETRY_TYPE_SETTING.get(settings) + : TELEMETRY_DEFAULT_TYPE_SETTING.get(settings); + return telemetryType; + } + + private void registerTelemetry(String key, Telemetry factory) { + if (telemetryFactories.putIfAbsent(key, factory) != null) { + throw new IllegalArgumentException("telemetry for name: " + key + " is already registered"); + } + } + +} diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java similarity index 89% rename from server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java rename to server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java index 329bc3892731a..a695cba0cc448 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerSettings.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java @@ -6,39 +6,40 @@ * compatible open source license. */ -package org.opensearch.telemetry.tracing; +package org.opensearch.telemetry; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.telemetry.tracing.Level; /** * Wrapper class to encapsulate tracing related settings */ -public class TracerSettings { +public class TelemetrySettings { public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( - "tracer.exporter.batch_size", + "telemetry.tracer.exporter.batch_size", 512, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( - "tracer.exporter.max_queue_size", + "telemetry.tracer.exporter.max_queue_size", 2048, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( - "tracer.exporter.delay", + "telemetry.tracer.exporter.delay", TimeValue.timeValueSeconds(2), Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting TRACER_LEVEL_SETTING = new Setting<>( - "tracer.level", + "telemetry.tracer.level", Level.ROOT.name(), Level::fromString, Setting.Property.NodeScope, @@ -46,7 +47,7 @@ public class TracerSettings { ); public static final Setting TRACER_ENABLED_SETTING = Setting.boolSetting( - "tracer.enabled", + "telemetry.tracer.enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic @@ -62,7 +63,7 @@ public class TracerSettings { private volatile TimeValue exporterDelay; - public TracerSettings(Settings settings, ClusterSettings clusterSettings) { + public TelemetrySettings(Settings settings, ClusterSettings clusterSettings) { this.tracerLevel = TRACER_LEVEL_SETTING.get(settings); this.tracingEnabled = TRACER_ENABLED_SETTING.get(settings); this.exporterBatchSize = TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings); diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java index c0e77d93b770a..63cde05f56cbb 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java @@ -56,6 +56,6 @@ private Optional spanFromThreadContext(String key) { } private Span spanFromHeader() { - return tracingTelemetry.getContextPropagator().extractSpanFromHeader(threadContext.getHeaders()); + return tracingTelemetry.getContextPropagator().extract(threadContext.getHeaders()); } } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index 5e8f50ca7a4c1..9b4d87f9fae39 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -11,13 +11,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.telemetry.tracing.noop.NoopTracer; import org.opensearch.threadpool.ThreadPool; import java.io.IOException; import java.util.Map; import java.util.function.BiConsumer; -import java.util.function.Supplier; /** * TracerManager represents a single global class that is used to access tracers. @@ -32,23 +32,20 @@ public class TracerManager { private volatile Tracer defaultTracer; private final Object mutex = new Object(); - private final TracerSettings tracerSettings; - private final Supplier telemetrySupplier; + private final TelemetrySettings telemetrySettings; + private final Telemetry telemetry; private final ThreadPool threadPool; /** * Initializes the TracerFactory singleton instance * - * @param tracerSettings tracer settings instance + * @param telemetrySettings tracer settings instance + * @param telemetry telemetry instance * @param threadPool thread pool instance */ - public static synchronized void initTracerManager( - TracerSettings tracerSettings, - Supplier tracerSupplier, - ThreadPool threadPool - ) { + public static synchronized void initTracerManager(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { if (INSTANCE == null) { - INSTANCE = new TracerManager(tracerSettings, tracerSupplier, threadPool); + INSTANCE = new TracerManager(telemetrySettings, telemetry, threadPool); } else { logger.warn("Trying to double initialize TracerFactory, skipping"); } @@ -79,9 +76,9 @@ public static void closeTracer() { } } - public TracerManager(TracerSettings tracerSettings, Supplier telemetrySupplier, ThreadPool threadPool) { - this.tracerSettings = tracerSettings; - this.telemetrySupplier = telemetrySupplier; + public TracerManager(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { + this.telemetrySettings = telemetrySettings; + this.telemetry = telemetry; this.threadPool = threadPool; } @@ -90,13 +87,11 @@ private Tracer tracer() { } private BiConsumer, Map> tracerHeaderInjector() { - return isTracingDisabled() - ? (x, y) -> {} - : telemetrySupplier.get().getTracingTelemetry().getContextPropagator().injectSpanInHeader(); + return isTracingDisabled() ? (x, y) -> {} : telemetry.getTracingTelemetry().getContextPropagator().inject(); } private boolean isTracingDisabled() { - return !tracerSettings.isTracingEnabled(); + return !telemetrySettings.isTracingEnabled(); } private Tracer getOrCreateDefaultTracerInstance() { @@ -104,12 +99,12 @@ private Tracer getOrCreateDefaultTracerInstance() { synchronized (mutex) { if (defaultTracer == null) { logger.info("Creating Otel tracer..."); - TracingTelemetry tracingTelemetry = telemetrySupplier.get().getTracingTelemetry(); + TracingTelemetry tracingTelemetry = telemetry.getTracingTelemetry(); TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( threadPool.getThreadContext(), tracingTelemetry ); - defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage, () -> tracerSettings.getTracerLevel()); + defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage, () -> telemetrySettings.getTracerLevel()); } } } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java deleted file mode 100644 index 9cc24eb835c05..0000000000000 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerModule.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.plugins.TracerPlugin; -import org.opensearch.telemetry.Telemetry; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - -/** - * A module for loading classes for tracer - * - * @opensearch.internal - */ -public class TracerModule { - - private static final String TRACER_TYPE_DEFAULT_KEY = "tracer.type.default"; - private static final String TRACER_TYPE_KEY = "tracer.type"; - - public static final Setting TRACER_DEFAULT_TYPE_SETTING = Setting.simpleString( - TRACER_TYPE_DEFAULT_KEY, - Setting.Property.NodeScope - ); - public static final Setting TRACER_TYPE_SETTING = Setting.simpleString(TRACER_TYPE_KEY, Setting.Property.NodeScope); - - private final Settings settings; - private final Map> tracerFactories = new HashMap<>(); - - public TracerModule(Settings settings, List tracerPlugins, TracerSettings tracerSettings) { - this.settings = settings; - - for (TracerPlugin tracerPlugin : tracerPlugins) { - Map> tracerFactory = tracerPlugin.getTelemetries(tracerSettings); - for (Map.Entry> entry : tracerFactory.entrySet()) { - registerTelemetry(entry.getKey(), entry.getValue()); - } - } - } - - public Supplier getTelemetrySupplier() { - final String tracerType = getTracerType(); - return tracerFactories.get(tracerType); - } - - private String getTracerType() { - final String tracerType = TRACER_DEFAULT_TYPE_SETTING.exists(settings) - ? TRACER_DEFAULT_TYPE_SETTING.get(settings) - : TRACER_TYPE_SETTING.get(settings); - return tracerType; - } - - private void registerTelemetry(String key, Supplier factory) { - if (tracerFactories.putIfAbsent(key, factory) != null) { - throw new IllegalArgumentException("tracer for name: " + key + " is already registered"); - } - } - -} diff --git a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java new file mode 100644 index 0000000000000..8708970d1fa57 --- /dev/null +++ b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java @@ -0,0 +1,118 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry; + +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.plugins.TelemetryPlugin; +import org.opensearch.telemetry.metrics.MetricsTelemetry; +import org.opensearch.telemetry.tracing.TracingTelemetry; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opensearch.telemetry.TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING; +import static org.opensearch.telemetry.TelemetryModule.TELEMETRY_TYPE_SETTING; + +public class TelemetryModuleTests extends OpenSearchTestCase { + + public void testGetTelemetryDefault() { + Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); + TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); + TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); + TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); + TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); + when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry1; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin1.getName()).thenReturn("otel"); + when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry2; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin2.getName()).thenReturn("foo"); + List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2); + + TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + + assertEquals(tracingTelemetry1, telemetryModule.getTelemetry().getTracingTelemetry()); + } + + public void testGetTelemetryCustom() { + Settings settings = Settings.builder() + .put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel") + .put(TELEMETRY_TYPE_SETTING.getKey(), "foo") + .build(); + Set> clusterSettings = getClusterSettings(); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, clusterSettings)); + TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); + TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); + TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); + TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); + when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry1; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin1.getName()).thenReturn("otel"); + when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry2; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin2.getName()).thenReturn("foo"); + List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2); + + TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + + assertEquals(tracingTelemetry2, telemetryModule.getTelemetry().getTracingTelemetry()); + } + + private Set> getClusterSettings() { + Set> allTracerSettings = new HashSet<>(); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); + + return allTracerSettings; + } +} diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java index cbb8da205a868..d70135027b3ba 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java @@ -15,6 +15,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; import org.opensearch.telemetry.tracing.noop.NoopTracer; @@ -44,20 +45,20 @@ public void testGetTracerWithUninitializedTracerFactory() { } public void testGetTracerWithTracingDisabledReturnsNoopTracer() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_ENABLED_SETTING.getKey(), false).build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(tracerSettings, null, mock(ThreadPool.class)); + Settings settings = Settings.builder().put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), false).build(); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); + TracerManager.initTracerManager(telemetrySettings, null, mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof NoopTracer); } public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { - Settings settings = Settings.builder().put(TracerSettings.TRACER_ENABLED_SETTING.getKey(), true).build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); + Settings settings = Settings.builder().put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), true).build(); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); Telemetry mockTelemetry = mock(Telemetry.class); when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); - TracerManager.initTracerManager(tracerSettings, () -> mockTelemetry, mock(ThreadPool.class)); + TracerManager.initTracerManager(telemetrySettings, mockTelemetry, mock(ThreadPool.class)); Tracer tracer = TracerManager.getTracer(); assertTrue(tracer instanceof DefaultTracer); @@ -66,7 +67,7 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { private Set> getClusterSettings() { Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); + ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); return allTracerSettings; } } diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java deleted file mode 100644 index 092abbcd89de5..0000000000000 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerModuleTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; -import org.opensearch.plugins.TracerPlugin; -import org.opensearch.telemetry.Telemetry; -import org.opensearch.telemetry.metrics.MetricsTelemetry; -import org.opensearch.test.OpenSearchTestCase; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.opensearch.telemetry.tracing.TracerModule.TRACER_DEFAULT_TYPE_SETTING; - -public class TracerModuleTests extends OpenSearchTestCase { - - public void testGetTelemetrySupplier() { - Settings settings = Settings.builder().put(TRACER_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); - TracerSettings tracerSettings = new TracerSettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerPlugin tracerPlugin1 = mock(TracerPlugin.class); - TracerPlugin tracerPlugin2 = mock(TracerPlugin.class); - TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); - TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - when(tracerPlugin1.getTelemetries(tracerSettings)).thenReturn(Map.of("otel", () -> new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry1; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(tracerPlugin2.getTelemetries(tracerSettings)).thenReturn(Map.of("foo", () -> new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry2; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - List tracerPlugins = List.of(tracerPlugin1, tracerPlugin2); - - TracerModule tracerModule = new TracerModule(settings, tracerPlugins, tracerSettings); - - assertEquals(tracingTelemetry1, tracerModule.getTelemetrySupplier().get().getTracingTelemetry()); - } - - private Set> getClusterSettings() { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TRACER)).stream().forEach((allTracerSettings::add)); - return allTracerSettings; - } -} From 51d2e3fe66ab0c297552f5fc157cfecc8bb922a0 Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 20 Jun 2023 21:35:33 +0530 Subject: [PATCH 22/38] Remove Level Signed-off-by: suranjay --- .../telemetry/tracing/AbstractSpan.java | 12 +- .../telemetry/tracing/DefaultTracer.java | 20 +--- .../opensearch/telemetry/tracing/Level.java | 108 ------------------ .../opensearch/telemetry/tracing/Span.java | 5 - .../telemetry/tracing/SpanFactory.java | 69 ----------- .../opensearch/telemetry/tracing/Tracer.java | 5 +- .../telemetry/tracing/TracingTelemetry.java | 3 +- .../telemetry/tracing/noop/NoopSpan.java | 6 +- .../telemetry/tracing/noop/NoopTracer.java | 3 +- .../telemetry/tracing/DefaultTracerTests.java | 41 +++---- .../telemetry/tracing/LevelTests.java | 28 ----- .../telemetry/tracing/SpanFactoryTests.java | 71 ------------ .../telemetry/tracing/OTelSpan.java | 4 +- .../tracing/OtelTracingContextPropagator.java | 2 +- .../tracing/OtelTracingTelemetry.java | 12 +- .../OTelTelemetryModulePluginTests.java | 3 +- .../telemetry/tracing/OTelSpanTests.java | 16 +-- .../OtelTracingContextPropagatorTests.java | 6 +- .../tracing/OtelTracingTelemetryTests.java | 6 +- .../common/settings/ClusterSettings.java | 1 - .../telemetry/TelemetrySettings.java | 21 ---- .../telemetry/tracing/TracerManager.java | 2 +- 22 files changed, 55 insertions(+), 389 deletions(-) delete mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java delete mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java delete mode 100644 libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java delete mode 100644 libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java index 8f634b82ec7d1..316edc971913e 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/AbstractSpan.java @@ -21,21 +21,15 @@ public abstract class AbstractSpan implements Span { * span's parent span */ private final Span parentSpan; - /** - * span's level - */ - private final Level level; /** * Base constructor * @param spanName name of the span * @param parentSpan span's parent span - * @param level span's level */ - protected AbstractSpan(String spanName, Span parentSpan, Level level) { + protected AbstractSpan(String spanName, Span parentSpan) { this.spanName = spanName; this.parentSpan = parentSpan; - this.level = level; } @Override @@ -48,8 +42,4 @@ public String getSpanName() { return spanName; } - @Override - public Level getLevel() { - return level; - } } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index a6092d1b5ce5d..e7535761a3c5f 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -10,7 +10,6 @@ import java.io.Closeable; import java.io.IOException; -import java.util.function.Supplier; /** * @@ -30,30 +29,21 @@ public class DefaultTracer implements Tracer { private final TracingTelemetry tracingTelemetry; private final TracerContextStorage tracerContextStorage; - private final Supplier levelSupplier; - private final SpanFactory spanFactory; /** * Creates DefaultTracer instance * * @param tracingTelemetry tracing telemetry instance * @param tracerContextStorage storage used for storing current span context - * @param levelSupplier configured level supplier */ - public DefaultTracer( - TracingTelemetry tracingTelemetry, - TracerContextStorage tracerContextStorage, - Supplier levelSupplier - ) { + public DefaultTracer(TracingTelemetry tracingTelemetry, TracerContextStorage tracerContextStorage) { this.tracingTelemetry = tracingTelemetry; this.tracerContextStorage = tracerContextStorage; - this.levelSupplier = levelSupplier; - this.spanFactory = new SpanFactory(levelSupplier, tracingTelemetry); } @Override - public Scope startSpan(String spanName, Level level) { - Span span = createSpan(spanName, getCurrentSpan(), level); + public Scope startSpan(String spanName) { + Span span = createSpan(spanName, getCurrentSpan()); setCurrentSpanInContext(span); addDefaultAttributes(span); return new ScopeImpl(() -> endSpan()); @@ -108,8 +98,8 @@ Span getCurrentSpan() { return tracerContextStorage.get(CURRENT_SPAN); } - private Span createSpan(String spanName, Span parentSpan, Level level) { - return spanFactory.createSpan(spanName, parentSpan, level); + private Span createSpan(String spanName, Span parentSpan) { + return tracingTelemetry.createSpan(spanName, parentSpan); } private void setCurrentSpanInContext(Span span) { diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java deleted file mode 100644 index ab83d10c7dd00..0000000000000 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Level.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import java.util.Arrays; - -/** - * The Level class defines a set of standard tracing levels that can be used to control tracing output. - * The tracing Level objects are ordered and are specified by ordered integers. - * Enabling tracing at a given level also enables tracing at all higher levels. - * - * Levels in descending order are - *
      - *
    • ROOT(highest value)
    • - *
    • TERSE
    • - *
    • INFO
    • - *
    • DEBUG
    • - *
    • TRACE(lowest value)
    • - *
    - * - */ -public enum Level { - /** - * ROOT is a tracing level indicating top level/root spans. - */ - ROOT((byte) 100), - - /** - * TERSE is a tracing level for critical spans - */ - TERSE((byte) 80), - - /** - * INFO is a tracing level used of generic spans - */ - INFO((byte) 60), - - /** - * DEBUG is a tracing level used for low level spans - */ - DEBUG((byte) 40), - - /** - * TRACE is the lowest level span - */ - TRACE((byte) 20); - - private final byte value; - - Level(byte value) { - this.value = value; - } - - /** - * Returns a mirrored Level object that matches the given name. Throws {@link IllegalArgumentException} if no match is found - * @param name string value - * @return Level corresponding to the given name - */ - public static Level fromString(String name) { - for (Level level : values()) { - if (level.name().equalsIgnoreCase(name)) { - return level; - } - } - throw new IllegalArgumentException( - "invalid value for tracing level [" + name + "], " + "must be in " + Arrays.asList(Level.values()) - ); - } - - /** - * Get the integer value for this level - * @return integer value of the level - */ - public int getValue() { - return value; - } - - /** - * Checks if the current level's value is equal or higher than the given level - * @param level to compare - * @return true if the current level's value is equal or higher than given level's value, false otherwise - */ - public boolean isHigherOrEqual(Level level) { - if (level != null) { - return this.value >= level.value; - } - return false; - } - - /** - * Checks if the current level's value is equal or lower than the given level - * @param level to compare - * @return true if the current level's value is equal or lower than given level's value, false otherwise - */ - public boolean isLessOrEqual(Level level) { - if (level != null) { - return this.value <= level.value; - } - return false; - } - -} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java index 6bc60a7dea8a6..0710b8a22a37f 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Span.java @@ -30,11 +30,6 @@ public interface Span { */ String getSpanName(); - /** - * Returns {@link Level} of the {@link Span} - */ - Level getLevel(); - /** * Adds string type attribute in the span * diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java deleted file mode 100644 index de7a0e48105c4..0000000000000 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.telemetry.tracing.noop.NoopSpan; - -import java.util.function.Supplier; - -/** - * Factory to create spans based on the configured level - */ -public final class SpanFactory { - - private final TracingTelemetry tracingTelemetry; - - private final Supplier levelSupplier; - - /** - * Creates SpanFactor instance with provided level supplier and tracing telemetry - * @param levelSupplier configured level supplier - * @param tracingTelemetry tracing telemetry - */ - public SpanFactory(Supplier levelSupplier, TracingTelemetry tracingTelemetry) { - this.levelSupplier = levelSupplier; - this.tracingTelemetry = tracingTelemetry; - } - - /** - * Creates span with provided arguments - * @param spanName name of the span - * @param parentSpan span's parent span - * @param level of the span - * @return span instance - */ - public Span createSpan(String spanName, Span parentSpan, Level level) { - return isLevelValid(level, parentSpan) - ? createDefaultSpan(spanName, parentSpan, level) - : createNoopSpan(spanName, parentSpan, level); - } - - private boolean isLevelValid(Level level, Span parentSpan) { - Level configuredLevel = levelSupplier.get(); - return isLevelEnabled(level, configuredLevel) && isLevelLowerThanParentSpanLevel(level, parentSpan); - } - - private boolean isLevelLowerThanParentSpanLevel(Level level, Span parentSpan) { - return parentSpan == null || (!(parentSpan instanceof NoopSpan) && level.isLessOrEqual(parentSpan.getLevel())); - } - - private boolean isLevelEnabled(Level level, Level configuredLevel) { - return level.isHigherOrEqual(configuredLevel); - } - - private Span createDefaultSpan(String spanName, Span parentSpan, Level level) { - Span telemetrySpan = tracingTelemetry.createSpan(spanName, parentSpan, level); - return telemetrySpan; - } - - private NoopSpan createNoopSpan(String spanName, Span parentSpan, Level level) { - return new NoopSpan(spanName, parentSpan, level); - } - -} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java index 6504bf7aef26d..1a27770eb9758 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java @@ -19,13 +19,12 @@ public interface Tracer extends Closeable { /** - * Starts the {@link Span} with given name and level + * Starts the {@link Span} with given name * * @param spanName span name - * @param level span tracing level * @return scope of the span, can be used with try-with-resources to close the span */ - Scope startSpan(String spanName, Level level); + Scope startSpan(String spanName); /** * Ends the current active {@link Span} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java index c1f80090172b9..16c76bd0cc141 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingTelemetry.java @@ -19,10 +19,9 @@ public interface TracingTelemetry extends Closeable { * Creates span with provided arguments * @param spanName name of the span * @param parentSpan span's parent span - * @param level span's level * @return span instance */ - Span createSpan(String spanName, Span parentSpan, Level level); + Span createSpan(String spanName, Span parentSpan); /** * provides tracing context propagator diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java index 6d0ffc991d447..07a4f4c7e4aad 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java @@ -10,7 +10,6 @@ import org.opensearch.telemetry.tracing.Span; import org.opensearch.telemetry.tracing.AbstractSpan; -import org.opensearch.telemetry.tracing.Level; /** * No-op implementation of Span @@ -21,10 +20,9 @@ public class NoopSpan extends AbstractSpan { * Creates a no-op span * @param spanName span's name * @param parentSpan span's parent span - * @param level span's level */ - public NoopSpan(String spanName, Span parentSpan, Level level) { - super(spanName, parentSpan, level); + public NoopSpan(String spanName, Span parentSpan) { + super(spanName, parentSpan); } @Override diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java index 6ef932af51e3c..9a36c8c665e97 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java @@ -8,7 +8,6 @@ package org.opensearch.telemetry.tracing.noop; -import org.opensearch.telemetry.tracing.Level; import org.opensearch.telemetry.tracing.Scope; import org.opensearch.telemetry.tracing.Tracer; @@ -25,7 +24,7 @@ public class NoopTracer implements Tracer { private NoopTracer() {} @Override - public Scope startSpan(String spanName, Level level) { + public Scope startSpan(String spanName) { return Scope.NO_OP; } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index 6581533b9d308..ce563c6ceacb4 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -12,7 +12,6 @@ import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; -import java.util.function.Supplier; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -25,7 +24,6 @@ public class DefaultTracerTests extends OpenSearchTestCase { private TracerContextStorage mockTracerContextStorage; private Span mockSpan; private Span mockParentSpan; - private Supplier levelSupplier; @Override public void setUp() throws Exception { @@ -39,16 +37,16 @@ public void tearDown() throws Exception { } public void testCreateSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); - defaultTracer.startSpan("span_name", Level.INFO); + defaultTracer.startSpan("span_name"); Assert.assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); } public void testEndSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); defaultTracer.endSpan(); @@ -57,16 +55,16 @@ public void testEndSpan() { } public void testEndSpanByClosingScope() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - try (Scope scope = defaultTracer.startSpan("span_name", Level.INFO)) { + DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + try (Scope scope = defaultTracer.startSpan("span_name")) { verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); } verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); } public void testAddSpanAttributeString() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); defaultTracer.addSpanAttribute("key", "value"); @@ -74,8 +72,8 @@ public void testAddSpanAttributeString() { } public void testAddSpanAttributeLong() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); defaultTracer.addSpanAttribute("key", 1L); @@ -83,8 +81,8 @@ public void testAddSpanAttributeLong() { } public void testAddSpanAttributeDouble() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); defaultTracer.addSpanAttribute("key", 1.0); @@ -92,8 +90,8 @@ public void testAddSpanAttributeDouble() { } public void testAddSpanAttributeBoolean() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); defaultTracer.addSpanAttribute("key", true); @@ -101,8 +99,8 @@ public void testAddSpanAttributeBoolean() { } public void testAddEvent() { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); - defaultTracer.startSpan("span_name", Level.INFO); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); + defaultTracer.startSpan("span_name"); defaultTracer.addSpanEvent("eventName"); @@ -110,7 +108,7 @@ public void testAddEvent() { } public void testClose() throws IOException { - Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage, levelSupplier); + Tracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); defaultTracer.close(); @@ -119,7 +117,6 @@ public void testClose() throws IOException { @SuppressWarnings("unchecked") private void setupMocks() { - levelSupplier = () -> Level.INFO; mockTracingTelemetry = mock(TracingTelemetry.class); mockSpan = mock(Span.class); mockParentSpan = mock(Span.class); @@ -127,12 +124,10 @@ private void setupMocks() { when(mockSpan.getSpanName()).thenReturn("span_name"); when(mockSpan.getSpanId()).thenReturn("span_id"); when(mockSpan.getTraceId()).thenReturn("trace_id"); - when(mockSpan.getLevel()).thenReturn(Level.INFO); when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); when(mockParentSpan.getTraceId()).thenReturn("trace_id"); - when(mockParentSpan.getLevel()).thenReturn(Level.INFO); when(mockTracerContextStorage.get(CURRENT_SPAN)).thenReturn(mockParentSpan, mockSpan); - when(mockTracingTelemetry.createSpan("span_name", mockParentSpan, Level.INFO)).thenReturn(mockSpan); + when(mockTracingTelemetry.createSpan("span_name", mockParentSpan)).thenReturn(mockSpan); } } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java deleted file mode 100644 index 4bc6e4f06bede..0000000000000 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/LevelTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.test.OpenSearchTestCase; - -public class LevelTests extends OpenSearchTestCase { - - public void testFromStringWithValidStrings() { - for (Level level : Level.values()) { - assertEquals(level, Level.fromString(level.name())); - } - } - - public void testFromStringWithInValidString() { - Exception exception = assertThrows(IllegalArgumentException.class, () -> Level.fromString("randomString")); - assertEquals( - "invalid value for tracing level [randomString], must be in [ROOT, TERSE, INFO, DEBUG, TRACE]", - exception.getMessage() - ); - } -} diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java deleted file mode 100644 index 5527d929f29bf..0000000000000 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/SpanFactoryTests.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing; - -import org.opensearch.telemetry.tracing.noop.NoopSpan; -import org.opensearch.test.OpenSearchTestCase; - -import java.util.function.Supplier; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SpanFactoryTests extends OpenSearchTestCase { - - public void testCreateSpanLevelDisabledReturnsNoopSpan() { - Supplier levelSupplier = () -> Level.ROOT; - SpanFactory spanFactory = new SpanFactory(levelSupplier, null); - - assertTrue(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); - } - - public void testCreateSpanLevelEnabledReturnsDefaultSpan() { - Supplier levelSupplier = () -> Level.INFO; - TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); - when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(levelSupplier, mockTracingTelemetry); - - assertFalse(spanFactory.createSpan("spanName", null, Level.INFO) instanceof NoopSpan); - } - - public void testCreateSpanWithSpanLevelLessThanParentSpanLeve() { - Supplier configuredLevelSupplier = () -> Level.INFO; - TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); - Span mockParentSpan = mock(Span.class); - when(mockParentSpan.getLevel()).thenReturn(Level.TERSE); - when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); - - assertFalse(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); - } - - public void testCreateSpanWithSpanLevelMoreThanParentSpanLeve() { - Supplier configuredLevelSupplier = () -> Level.INFO; - TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); - Span mockParentSpan = mock(Span.class); - when(mockParentSpan.getLevel()).thenReturn(Level.DEBUG); - when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); - - assertTrue(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); - } - - public void testCreateSpanWithSpanLevelSameAsParentSpanLeve() { - Supplier configuredLevelSupplier = () -> Level.INFO; - TracingTelemetry mockTracingTelemetry = mock(TracingTelemetry.class); - Span mockParentSpan = mock(Span.class); - when(mockParentSpan.getLevel()).thenReturn(Level.TERSE); - when(mockTracingTelemetry.createSpan(eq("spanName"), any(), eq(Level.INFO))).thenReturn(mock(Span.class)); - SpanFactory spanFactory = new SpanFactory(configuredLevelSupplier, mockTracingTelemetry); - - assertFalse(spanFactory.createSpan("spanName", mockParentSpan, Level.INFO) instanceof NoopSpan); - } -} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index a78db1d04b14c..6760d44c85861 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -18,8 +18,8 @@ class OTelSpan extends AbstractSpan { private final Span otelSpan; - public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan, Level level) { - super(spanName, parentSpan, level); + public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan) { + super(spanName, parentSpan); this.otelSpan = span; } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index 3b02566209645..ecc62245081e3 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -42,7 +42,7 @@ public Span extract(Map props) { Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), props, TEXT_MAP_GETTER); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OTelSpan(PROPAGATED_SPAN, span, null, Level.ROOT); + return new OTelSpan(PROPAGATED_SPAN, span, null); } return null; } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java index 660f1ac8cde28..aad7773bf456c 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java @@ -46,8 +46,8 @@ public void close() { } @Override - public Span createSpan(String spanName, Span parentSpan, Level level) { - return createOtelSpan(spanName, parentSpan, level); + public Span createSpan(String spanName, Span parentSpan) { + return createOtelSpan(spanName, parentSpan); } @Override @@ -55,12 +55,12 @@ public TracingContextPropagator getContextPropagator() { return new OtelTracingContextPropagator(openTelemetry); } - private Span createOtelSpan(String spanName, Span parentSpan, Level level) { - io.opentelemetry.api.trace.Span otelSpan = createOtelSpan(spanName, parentSpan); - return new OTelSpan(spanName, otelSpan, parentSpan, level); + private Span createOtelSpan(String spanName, Span parentSpan) { + io.opentelemetry.api.trace.Span otelSpan = otelSpan(spanName, parentSpan); + return new OTelSpan(spanName, otelSpan, parentSpan); } - io.opentelemetry.api.trace.Span createOtelSpan(String spanName, Span parentOTelSpan) { + io.opentelemetry.api.trace.Span otelSpan(String spanName, Span parentOTelSpan) { return parentOTelSpan == null || !(parentOTelSpan instanceof OTelSpan) ? otelTracer.spanBuilder(spanName).startSpan() : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getOtelSpan())).startSpan(); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java index 0dbc70a0f97b6..e24154113ecc3 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -13,7 +13,6 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.Level; import org.opensearch.telemetry.tracing.OtelTracingTelemetry; import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; @@ -47,7 +46,7 @@ public void testAdditionalSettingWithTracingFeatureEnabled() { public void testGetTelemetry() throws IOException { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); - Settings settings = Settings.builder().put(TelemetrySettings.TRACER_LEVEL_SETTING.getKey(), Level.INFO).build(); + Settings settings = Settings.builder().build(); ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterSettings); OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java index 604094d606278..ac849e620673a 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java @@ -25,14 +25,14 @@ public class OTelSpanTests extends OpenSearchTestCase { public void testEndSpanTest() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.endSpan(); verify(mockSpan).end(); } public void testAddAttributeString() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.addAttribute("key", "value"); verify(mockSpan).setAttribute("key", "value"); @@ -40,7 +40,7 @@ public void testAddAttributeString() { public void testAddAttributeLong() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.addAttribute("key", 1L); verify(mockSpan).setAttribute("key", 1L); @@ -48,7 +48,7 @@ public void testAddAttributeLong() { public void testAddAttributeDouble() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.addAttribute("key", 1.0); verify(mockSpan).setAttribute("key", 1.0); @@ -56,7 +56,7 @@ public void testAddAttributeDouble() { public void testAddAttributeBoolean() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.addAttribute("key", true); verify(mockSpan).setAttribute("key", true); @@ -64,7 +64,7 @@ public void testAddAttributeBoolean() { public void testAddEvent() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); oTelSpan.addEvent("eventName"); verify(mockSpan).addEvent("eventName"); @@ -72,14 +72,14 @@ public void testAddEvent() { public void testGetTraceId() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); assertEquals(TRACE_ID, oTelSpan.getTraceId()); } public void testGetSpanId() { Span mockSpan = getMockSpan(); - OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan oTelSpan = new OTelSpan("spanName", mockSpan, null); assertEquals(SPAN_ID, oTelSpan.getSpanId()); } diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index 1b209ce5558ca..b443b29f62f4c 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -34,7 +34,7 @@ public class OtelTracingContextPropagatorTests extends OpenSearchTestCase { public void testAddTracerContextToHeader() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); + OTelSpan span = new OTelSpan("spanName", mockSpan, null); AtomicReference spanHolder = new AtomicReference<>(span); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); @@ -49,8 +49,8 @@ public void testAddTracerContextToHeader() { public void testAddTracerContextToHeaderWithNoopSpan() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - OTelSpan span = new OTelSpan("spanName", mockSpan, null, Level.INFO); - NoopSpan noopSpan = new NoopSpan("noopSpanName", span, Level.INFO); + OTelSpan span = new OTelSpan("spanName", mockSpan, null); + NoopSpan noopSpan = new NoopSpan("noopSpanName", span); AtomicReference spanHolder = new AtomicReference<>(noopSpan); Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java index e211a7a1b186b..3cd7af2881a47 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java @@ -30,7 +30,7 @@ public void testCreateSpanWithoutParent() { when(mockSpanBuilder.startSpan()).thenReturn(mock(io.opentelemetry.api.trace.Span.class)); TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); - Span span = tracingTelemetry.createSpan("span_name", null, Level.INFO); + Span span = tracingTelemetry.createSpan("span_name", null); verify(mockSpanBuilder, never()).setParent(any()); assertNull(span.getParentSpan()); @@ -45,10 +45,10 @@ public void testCreateSpanWithParent() { when(mockSpanBuilder.setParent(any())).thenReturn(mockSpanBuilder); when(mockSpanBuilder.startSpan()).thenReturn(mock(io.opentelemetry.api.trace.Span.class)); - Span parentSpan = new OTelSpan("parent_span", mock(io.opentelemetry.api.trace.Span.class), null, Level.INFO); + Span parentSpan = new OTelSpan("parent_span", mock(io.opentelemetry.api.trace.Span.class), null); TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); - Span span = tracingTelemetry.createSpan("span_name", parentSpan, Level.INFO); + Span span = tracingTelemetry.createSpan("span_name", parentSpan); verify(mockSpanBuilder).setParent(any()); assertNotNull(span.getParentSpan()); diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 246d663bcd2f9..2405bb0435a0a 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -680,7 +680,6 @@ public void apply(Settings value, Settings current, Settings previous) { List.of(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING), List.of(FeatureFlags.TELEMETRY), List.of( - TelemetrySettings.TRACER_LEVEL_SETTING, TelemetrySettings.TRACER_ENABLED_SETTING, TelemetrySettings.TRACER_EXPORTER_DELAY_SETTING, TelemetrySettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java index a695cba0cc448..c62e95482bc6e 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java @@ -12,7 +12,6 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.telemetry.tracing.Level; /** * Wrapper class to encapsulate tracing related settings @@ -38,14 +37,6 @@ public class TelemetrySettings { Setting.Property.NodeScope, Setting.Property.Dynamic ); - public static final Setting TRACER_LEVEL_SETTING = new Setting<>( - "telemetry.tracer.level", - Level.ROOT.name(), - Level::fromString, - Setting.Property.NodeScope, - Setting.Property.Dynamic - ); - public static final Setting TRACER_ENABLED_SETTING = Setting.boolSetting( "telemetry.tracer.enabled", false, @@ -53,8 +44,6 @@ public class TelemetrySettings { Setting.Property.Dynamic ); - private volatile Level tracerLevel; - private volatile boolean tracingEnabled; private volatile int exporterBatchSize; @@ -64,23 +53,17 @@ public class TelemetrySettings { private volatile TimeValue exporterDelay; public TelemetrySettings(Settings settings, ClusterSettings clusterSettings) { - this.tracerLevel = TRACER_LEVEL_SETTING.get(settings); this.tracingEnabled = TRACER_ENABLED_SETTING.get(settings); this.exporterBatchSize = TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings); this.exporterMaxQueueSize = TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING.get(settings); this.exporterDelay = TRACER_EXPORTER_DELAY_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(TRACER_LEVEL_SETTING, this::setTracerLevel); clusterSettings.addSettingsUpdateConsumer(TRACER_ENABLED_SETTING, this::setTracingEnabled); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_BATCH_SIZE_SETTING, this::setExporterBatchSize); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, this::setExporterMaxQueueSize); clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_DELAY_SETTING, this::setExporterDelay); } - public void setTracerLevel(Level tracerLevel) { - this.tracerLevel = tracerLevel; - } - public void setTracingEnabled(boolean tracingEnabled) { this.tracingEnabled = tracingEnabled; } @@ -97,10 +80,6 @@ public void setExporterDelay(TimeValue exporterDelay) { this.exporterDelay = exporterDelay; } - public Level getTracerLevel() { - return tracerLevel; - } - public boolean isTracingEnabled() { return tracingEnabled; } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java index 9b4d87f9fae39..57a1a55214cd8 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java @@ -104,7 +104,7 @@ private Tracer getOrCreateDefaultTracerInstance() { threadPool.getThreadContext(), tracingTelemetry ); - defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage, () -> telemetrySettings.getTracerLevel()); + defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage); } } } From 55e503930e5db70b0add533096140a82473c507e Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 20 Jun 2023 21:49:46 +0530 Subject: [PATCH 23/38] Remove parent override Signed-off-by: suranjay --- .../tracing/OtelTracingContextPropagator.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index ecc62245081e3..530c4d9d372d4 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -12,7 +12,6 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapSetter; -import org.opensearch.telemetry.tracing.noop.NoopSpan; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -55,8 +54,11 @@ public BiConsumer, Map> inject() { @SuppressWarnings("unchecked") AtomicReference currentSpanRef = (AtomicReference) transientHeaders.get(CURRENT_SPAN); Span currentSpan = currentSpanRef.get(); - OTelSpan oTelSpan = getLastValidSpanInChain(currentSpan); - openTelemetry.getPropagators().getTextMapPropagator().inject(context(oTelSpan), requestHeaders, TEXT_MAP_SETTER); + if (currentSpan instanceof OTelSpan) { + openTelemetry.getPropagators() + .getTextMapPropagator() + .inject(context((OTelSpan) currentSpan), requestHeaders, TEXT_MAP_SETTER); + } } } }; @@ -66,13 +68,6 @@ private static Context context(OTelSpan oTelSpan) { return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); } - private static OTelSpan getLastValidSpanInChain(Span span) { - while (span instanceof NoopSpan) { - span = span.getParentSpan(); - } - return (OTelSpan) span; - } - private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { if (carrier != null) { carrier.put(key, value); From abc3029a0857f6f0b6026b4873e24a2eabf1ab0d Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 21 Jun 2023 00:15:18 +0530 Subject: [PATCH 24/38] Address PR comments Signed-off-by: suranjay --- .../telemetry/OTelResourceProvider.java | 26 ++++---- .../telemetry/OTelTelemetryModulePlugin.java | 38 +++++++++-- .../opensearch/telemetry/package-info.java | 12 ++++ .../tracing/OtelTracingContextPropagator.java | 4 +- .../telemetry/tracing/PropagatedSpan.java | 19 ++++++ .../OTelTelemetryModulePluginTests.java | 7 +- .../OtelTracingContextPropagatorTests.java | 16 ----- .../common/settings/ClusterSettings.java | 9 +-- .../opensearch/plugins/TelemetryPlugin.java | 4 +- .../opensearch/telemetry/TelemetryModule.java | 27 ++++---- .../telemetry/TelemetrySettings.java | 56 ---------------- .../opensearch/telemetry/package-info.java | 12 ++++ .../telemetry/TelemetryModuleTests.java | 66 +++++++++++++++---- 13 files changed, 163 insertions(+), 133 deletions(-) create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java create mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java create mode 100644 server/src/main/java/org/opensearch/telemetry/package-info.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java index 17705c6873775..cf441b87e3d13 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java @@ -19,33 +19,33 @@ import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import org.opensearch.common.settings.Settings; import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; import java.util.concurrent.TimeUnit; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_DELAY_SETTING; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; + /** * This class encapsulates all OpenTelemetry related resources */ final class OTelResourceProvider { - static OpenTelemetry get(TelemetrySettings telemetrySettings) { + static OpenTelemetry get(Settings settings) { return get( - telemetrySettings, + settings, new FileSpanExporter(), ContextPropagators.create(W3CTraceContextPropagator.getInstance()), Sampler.alwaysOn() ); } - static OpenTelemetry get( - TelemetrySettings telemetrySettings, - SpanExporter spanExporter, - ContextPropagators contextPropagators, - Sampler sampler - ) { + static OpenTelemetry get(Settings settings, SpanExporter spanExporter, ContextPropagators contextPropagators, Sampler sampler) { Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(spanProcessor(telemetrySettings, spanExporter)) + .addSpanProcessor(spanProcessor(settings, spanExporter)) .setResource(resource) .setSampler(sampler) .build(); @@ -53,11 +53,11 @@ static OpenTelemetry get( return OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).setPropagators(contextPropagators).buildAndRegisterGlobal(); } - private static BatchSpanProcessor spanProcessor(TelemetrySettings telemetrySettings, SpanExporter spanExporter) { + private static BatchSpanProcessor spanProcessor(Settings settings, SpanExporter spanExporter) { return BatchSpanProcessor.builder(spanExporter) - .setScheduleDelay(telemetrySettings.getExporterDelay().getSeconds(), TimeUnit.SECONDS) - .setMaxExportBatchSize(telemetrySettings.getExporterBatchSize()) - .setMaxQueueSize(telemetrySettings.getExporterMaxQueueSize()) + .setScheduleDelay(TRACER_EXPORTER_DELAY_SETTING.get(settings).getSeconds(), TimeUnit.SECONDS) + .setMaxExportBatchSize(TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings)) + .setMaxQueueSize(TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING.get(settings)) .build(); } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java index 759df136288ea..e9a6ff1a0ed66 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -8,7 +8,9 @@ package org.opensearch.telemetry; +import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.TelemetryPlugin; @@ -16,6 +18,8 @@ import org.opensearch.telemetry.tracing.OtelTelemetryImpl; import org.opensearch.telemetry.tracing.OtelTracingTelemetry; +import java.util.Arrays; +import java.util.List; import java.util.Optional; import static org.opensearch.common.util.FeatureFlags.TELEMETRY; @@ -27,11 +31,37 @@ public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin static final String OTEL_TRACER_NAME = "otel"; + public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( + "telemetry.tracer.exporter.batch_size", + 512, + 1, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( + "telemetry.tracer.exporter.max_queue_size", + 2048, + 1, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( + "telemetry.tracer.exporter.delay", + TimeValue.timeValueSeconds(2), + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + /** * No-args constructor */ public OTelTelemetryModulePlugin() {} + @Override + public List> getSettings() { + return Arrays.asList(TRACER_EXPORTER_BATCH_SIZE_SETTING, TRACER_EXPORTER_DELAY_SETTING, TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING); + } + @Override public Settings additionalSettings() { if (FeatureFlags.isEnabled(TELEMETRY)) { @@ -44,8 +74,8 @@ public Settings additionalSettings() { } @Override - public Optional getTelemetry(TelemetrySettings telemetrySettings) { - return Optional.of(telemetry(telemetrySettings)); + public Optional getTelemetry(Settings settings) { + return Optional.of(telemetry(settings)); } @Override @@ -53,8 +83,8 @@ public String getName() { return OTEL_TRACER_NAME; } - private Telemetry telemetry(TelemetrySettings telemetrySettings) { - return new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(telemetrySettings)), new MetricsTelemetry() { + private Telemetry telemetry(Settings settings) { + return new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(settings)), new MetricsTelemetry() { }); } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java new file mode 100644 index 0000000000000..4545f0ef5990e --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * This package contains classes needed for telemetry. + */ +package org.opensearch.telemetry; diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index 530c4d9d372d4..09947cb15f38e 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -24,8 +24,6 @@ */ public class OtelTracingContextPropagator implements TracingContextPropagator { - private static final String PROPAGATED_SPAN = "propagated_span"; - private final OpenTelemetry openTelemetry; /** @@ -41,7 +39,7 @@ public Span extract(Map props) { Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), props, TEXT_MAP_GETTER); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new OTelSpan(PROPAGATED_SPAN, span, null); + return new PropagatedSpan(span); } return null; } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java new file mode 100644 index 0000000000000..b899eca85351b --- /dev/null +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +/** + * Propagated span through context propagation + */ +public class PropagatedSpan extends OTelSpan { + + public PropagatedSpan(io.opentelemetry.api.trace.Span span) { + super(null, span, null); + } +} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java index e24154113ecc3..a36e228cecde9 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -17,7 +17,6 @@ import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; -import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -43,14 +42,12 @@ public void testAdditionalSettingWithTracingFeatureEnabled() { assertFalse(settings.isEmpty()); } - public void testGetTelemetry() throws IOException { + public void testGetTelemetry() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); Settings settings = Settings.builder().build(); - ClusterSettings clusterSettings = new ClusterSettings(settings, allTracerSettings); - TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterSettings); OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(); - Optional tracer = oTelTracerModulePlugin.getTelemetry(telemetrySettings); + Optional tracer = oTelTracerModulePlugin.getTelemetry(settings); assertEquals(OTEL_TRACER_NAME, oTelTracerModulePlugin.getName()); TracingTelemetry tracingTelemetry = tracer.get().getTracingTelemetry(); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index b443b29f62f4c..2f7a5474c808e 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -15,7 +15,6 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.ContextPropagators; -import org.opensearch.telemetry.tracing.noop.NoopSpan; import org.opensearch.test.OpenSearchTestCase; import java.util.HashMap; @@ -46,21 +45,6 @@ public void testAddTracerContextToHeader() { assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } - public void testAddTracerContextToHeaderWithNoopSpan() { - Span mockSpan = mock(Span.class); - when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - OTelSpan span = new OTelSpan("spanName", mockSpan, null); - NoopSpan noopSpan = new NoopSpan("noopSpanName", span); - AtomicReference spanHolder = new AtomicReference<>(noopSpan); - Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); - Map requestHeaders = new HashMap<>(); - OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); - when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); - TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); - tracingContextPropagator.inject().accept(requestHeaders, transientHeaders); - assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); - } - public void testExtractTracerContextFromHeader() { Map requestHeaders = new HashMap<>(); requestHeaders.put("traceparent", "00-" + TRACE_ID + "-" + SPAN_ID + "-00"); diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 2405bb0435a0a..76bfba1e85618 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -679,13 +679,6 @@ public void apply(Settings value, Settings current, Settings previous) { List.of(FeatureFlags.CONCURRENT_SEGMENT_SEARCH), List.of(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING), List.of(FeatureFlags.TELEMETRY), - List.of( - TelemetrySettings.TRACER_ENABLED_SETTING, - TelemetrySettings.TRACER_EXPORTER_DELAY_SETTING, - TelemetrySettings.TRACER_EXPORTER_BATCH_SIZE_SETTING, - TelemetrySettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, - TelemetryModule.TELEMETRY_TYPE_SETTING, - TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING - ) + List.of(TelemetrySettings.TRACER_ENABLED_SETTING, TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING) ); } diff --git a/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java index 66033df394d9f..e133a7d5a3a17 100644 --- a/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java @@ -8,8 +8,8 @@ package org.opensearch.plugins; +import org.opensearch.common.settings.Settings; import org.opensearch.telemetry.Telemetry; -import org.opensearch.telemetry.TelemetrySettings; import java.util.Optional; @@ -18,7 +18,7 @@ */ public interface TelemetryPlugin { - Optional getTelemetry(TelemetrySettings telemetrySettings); + Optional getTelemetry(Settings settings); String getName(); diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java index 23b52fd2ad2f0..2b2e5320f1836 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java @@ -25,13 +25,11 @@ public class TelemetryModule { private static final String TELEMETRY_TYPE_DEFAULT = "telemetry.type.default"; - private static final String TELEMETRY_TYPE = "telemetry.type"; public static final Setting TELEMETRY_DEFAULT_TYPE_SETTING = Setting.simpleString( TELEMETRY_TYPE_DEFAULT, Setting.Property.NodeScope ); - public static final Setting TELEMETRY_TYPE_SETTING = Setting.simpleString(TELEMETRY_TYPE, Setting.Property.NodeScope); private final Settings settings; private final Map telemetryFactories = new HashMap<>(); @@ -40,7 +38,7 @@ public TelemetryModule(Settings settings, List telemetryPlugins this.settings = settings; for (TelemetryPlugin telemetryPlugin : telemetryPlugins) { - Optional telemetry = telemetryPlugin.getTelemetry(telemetrySettings); + Optional telemetry = telemetryPlugin.getTelemetry(settings); if (telemetry.isPresent()) { registerTelemetry(telemetryPlugin.getName(), telemetry.get()); } @@ -48,21 +46,26 @@ public TelemetryModule(Settings settings, List telemetryPlugins } public Telemetry getTelemetry() { - final String telemetryType = getTelemetryType(); - return telemetryFactories.get(telemetryType); - } - - private String getTelemetryType() { - final String telemetryType = TELEMETRY_TYPE_SETTING.exists(settings) - ? TELEMETRY_TYPE_SETTING.get(settings) - : TELEMETRY_DEFAULT_TYPE_SETTING.get(settings); - return telemetryType; + // if only default(Otel) telemetry is registered, return it + if (telemetryFactories.size() == 1) { + return telemetryFactories.values().stream().findFirst().get(); + } + // if custom telemetry is also registered, return custom telemetry + return telemetryFactories.entrySet() + .stream() + .filter(entry -> !entry.getValue().equals(TELEMETRY_DEFAULT_TYPE_SETTING.get(settings))) + .map(entry -> entry.getValue()) + .findFirst() + .get(); } private void registerTelemetry(String key, Telemetry factory) { if (telemetryFactories.putIfAbsent(key, factory) != null) { throw new IllegalArgumentException("telemetry for name: " + key + " is already registered"); } + if (telemetryFactories.size() == 3) { + throw new IllegalArgumentException("Cannot register more than one custom telemetry"); + } } } diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java index c62e95482bc6e..7c9e0d5ac8097 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetrySettings.java @@ -11,32 +11,11 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.common.unit.TimeValue; /** * Wrapper class to encapsulate tracing related settings */ public class TelemetrySettings { - public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( - "telemetry.tracer.exporter.batch_size", - 512, - 1, - Setting.Property.NodeScope, - Setting.Property.Dynamic - ); - public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( - "telemetry.tracer.exporter.max_queue_size", - 2048, - 1, - Setting.Property.NodeScope, - Setting.Property.Dynamic - ); - public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( - "telemetry.tracer.exporter.delay", - TimeValue.timeValueSeconds(2), - Setting.Property.NodeScope, - Setting.Property.Dynamic - ); public static final Setting TRACER_ENABLED_SETTING = Setting.boolSetting( "telemetry.tracer.enabled", false, @@ -46,53 +25,18 @@ public class TelemetrySettings { private volatile boolean tracingEnabled; - private volatile int exporterBatchSize; - - private volatile int exporterMaxQueueSize; - - private volatile TimeValue exporterDelay; - public TelemetrySettings(Settings settings, ClusterSettings clusterSettings) { this.tracingEnabled = TRACER_ENABLED_SETTING.get(settings); - this.exporterBatchSize = TRACER_EXPORTER_BATCH_SIZE_SETTING.get(settings); - this.exporterMaxQueueSize = TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING.get(settings); - this.exporterDelay = TRACER_EXPORTER_DELAY_SETTING.get(settings); clusterSettings.addSettingsUpdateConsumer(TRACER_ENABLED_SETTING, this::setTracingEnabled); - clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_BATCH_SIZE_SETTING, this::setExporterBatchSize); - clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING, this::setExporterMaxQueueSize); - clusterSettings.addSettingsUpdateConsumer(TRACER_EXPORTER_DELAY_SETTING, this::setExporterDelay); } public void setTracingEnabled(boolean tracingEnabled) { this.tracingEnabled = tracingEnabled; } - public void setExporterBatchSize(int exporterBatchSize) { - this.exporterBatchSize = exporterBatchSize; - } - - public void setExporterMaxQueueSize(int exporterMaxQueueSize) { - this.exporterMaxQueueSize = exporterMaxQueueSize; - } - - public void setExporterDelay(TimeValue exporterDelay) { - this.exporterDelay = exporterDelay; - } - public boolean isTracingEnabled() { return tracingEnabled; } - public int getExporterBatchSize() { - return exporterBatchSize; - } - - public int getExporterMaxQueueSize() { - return exporterMaxQueueSize; - } - - public TimeValue getExporterDelay() { - return exporterDelay; - } } diff --git a/server/src/main/java/org/opensearch/telemetry/package-info.java b/server/src/main/java/org/opensearch/telemetry/package-info.java new file mode 100644 index 0000000000000..4545f0ef5990e --- /dev/null +++ b/server/src/main/java/org/opensearch/telemetry/package-info.java @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * This package contains classes needed for telemetry. + */ +package org.opensearch.telemetry; diff --git a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java index 8708970d1fa57..296e9a380a904 100644 --- a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java +++ b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java @@ -25,7 +25,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opensearch.telemetry.TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING; -import static org.opensearch.telemetry.TelemetryModule.TELEMETRY_TYPE_SETTING; public class TelemetryModuleTests extends OpenSearchTestCase { @@ -33,10 +32,35 @@ public void testGetTelemetryDefault() { Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); + TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); + when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry1; + } + + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin1.getName()).thenReturn("otel"); + List telemetryPlugins = List.of(telemetryPlugin1); + + TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + + assertEquals(tracingTelemetry1, telemetryModule.getTelemetry().getTracingTelemetry()); + } + + public void testGetTelemetryCustom() { + Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); + Set> clusterSettings = getClusterSettings(); + TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, clusterSettings)); + TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry1; @@ -48,7 +72,7 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin2.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry2; @@ -64,21 +88,20 @@ public MetricsTelemetry getMetricsTelemetry() { TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); - assertEquals(tracingTelemetry1, telemetryModule.getTelemetry().getTracingTelemetry()); + assertEquals(tracingTelemetry2, telemetryModule.getTelemetry().getTracingTelemetry()); } - public void testGetTelemetryCustom() { - Settings settings = Settings.builder() - .put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel") - .put(TELEMETRY_TYPE_SETTING.getKey(), "foo") - .build(); + public void testGetTelemetryWithMoreThanOneCustomTelemetry() { + Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); Set> clusterSettings = getClusterSettings(); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, clusterSettings)); TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); + TelemetryPlugin telemetryPlugin3 = mock(TelemetryPlugin.class); TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + TracingTelemetry tracingTelemetry3 = mock(TracingTelemetry.class); + when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry1; @@ -90,7 +113,7 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin2.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry2; @@ -102,11 +125,26 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin2.getName()).thenReturn("foo"); - List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2); + when(telemetryPlugin3.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + @Override + public TracingTelemetry getTracingTelemetry() { + return tracingTelemetry3; + } - TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + @Override + public MetricsTelemetry getMetricsTelemetry() { + return null; + } + })); + when(telemetryPlugin3.getName()).thenReturn("bar"); + try { + List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2, telemetryPlugin3); + TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + } catch (Exception e) { + assertTrue(e instanceof IllegalArgumentException); + assertEquals("Cannot register more than one custom telemetry", e.getMessage()); + } - assertEquals(tracingTelemetry2, telemetryModule.getTelemetry().getTracingTelemetry()); } private Set> getClusterSettings() { From c5b11530e65e83bde6ebf616bab649457f633df0 Mon Sep 17 00:00:00 2001 From: suranjay Date: Wed, 21 Jun 2023 00:49:00 +0530 Subject: [PATCH 25/38] fix javadoc errors Signed-off-by: suranjay --- .../org/opensearch/telemetry/OTelTelemetryModulePlugin.java | 6 +++--- .../org/opensearch/telemetry/tracing/PropagatedSpan.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java index e9a6ff1a0ed66..fc48639f3c056 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -31,21 +31,21 @@ public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin static final String OTEL_TRACER_NAME = "otel"; - public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( + static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( "telemetry.tracer.exporter.batch_size", 512, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); - public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( + static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( "telemetry.tracer.exporter.max_queue_size", 2048, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); - public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( + static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( "telemetry.tracer.exporter.delay", TimeValue.timeValueSeconds(2), Setting.Property.NodeScope, diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java index b899eca85351b..90afe1278150c 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java @@ -13,6 +13,10 @@ */ public class PropagatedSpan extends OTelSpan { + /** + * Creates PropagatedSpan + * @param span otel propagated span + */ public PropagatedSpan(io.opentelemetry.api.trace.Span span) { super(null, span, null); } From 39aa3a7c650bb98f392b3490ca0100440a3bef89 Mon Sep 17 00:00:00 2001 From: suranjay Date: Thu, 22 Jun 2023 16:46:47 +0530 Subject: [PATCH 26/38] Address PR comments Signed-off-by: suranjay --- distribution/src/config/log4j2.properties | 19 -- libs/telemetry/build.gradle | 19 -- .../telemetry/tracing/SpanReference.java | 29 +++ .../tracing/TracingContextPropagator.java | 8 +- modules/telemetry-otel/build.gradle | 7 +- ...telemetry-exporter-logging-1.26.0.jar.sha1 | 1 + ...opentelemetry-exporter-logging-LICENSE.txt | 202 ++++++++++++++++++ .../opentelemetry-exporter-logging-NOTICE.txt | 0 .../telemetry/OTelResourceProvider.java | 4 +- .../telemetry/OTelTelemetryModulePlugin.java | 21 +- ...gatedSpan.java => OTelPropagatedSpan.java} | 6 +- .../tracing/OtelTracingContextPropagator.java | 27 +-- .../tracing/exporter/FileSpanExporter.java | 86 -------- .../tracing/exporter/package-info.java | 12 -- .../OTelTelemetryModulePluginTests.java | 8 +- .../OtelTracingContextPropagatorTests.java | 6 +- .../exporter/FileSpanExporterTests.java | 94 -------- .../tracing/exporter/MockAppender.java | 37 ---- .../common/util/concurrent/ThreadContext.java | 16 +- .../main/java/org/opensearch/node/Node.java | 13 +- .../opensearch/plugins/TelemetryPlugin.java | 4 +- .../opensearch/telemetry/TelemetryModule.java | 2 +- .../telemetry/tracing/NoopTracerFactory.java | 31 +++ ...hreadContextBasedTracerContextStorage.java | 11 +- ...{TracerManager.java => TracerFactory.java} | 69 ++---- .../telemetry/TelemetryModuleTests.java | 12 +- ...agerTests.java => TracerFactoryTests.java} | 23 +- 27 files changed, 364 insertions(+), 403 deletions(-) create mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java create mode 100644 modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 create mode 100644 modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt create mode 100644 modules/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt rename modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/{PropagatedSpan.java => OTelPropagatedSpan.java} (72%) delete mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java delete mode 100644 modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java delete mode 100644 modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java delete mode 100644 modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java create mode 100644 server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java rename server/src/main/java/org/opensearch/telemetry/tracing/{TracerManager.java => TracerFactory.java} (57%) rename server/src/test/java/org/opensearch/telemetry/tracing/{TracerManagerTests.java => TracerFactoryTests.java} (76%) diff --git a/distribution/src/config/log4j2.properties b/distribution/src/config/log4j2.properties index 7017ef854c96d..bb27aaf2e22e6 100644 --- a/distribution/src/config/log4j2.properties +++ b/distribution/src/config/log4j2.properties @@ -232,22 +232,3 @@ logger.task_detailslog_rolling.level = trace logger.task_detailslog_rolling.appenderRef.task_detailslog_rolling.ref = task_detailslog_rolling logger.task_detailslog_rolling.appenderRef.task_detailslog_rolling_old.ref = task_detailslog_rolling_old logger.task_detailslog_rolling.additivity = false -######## Distributed Tracing logs JSON #################### -appender.tracing_log_rolling.type = RollingFile -appender.tracing_log_rolling.name = tracing_log_rolling -appender.tracing_log_rolling.fileName = ${sys:opensearch.logs.base_path}${sys:file.separator}${sys:opensearch.logs.cluster_name}_tracing.trace -appender.tracing_log_rolling.filePermissions = rw-r----- -appender.tracing_log_rolling.layout.type = PatternLayout -appender.tracing_log_rolling.layout.pattern = %m%n -appender.tracing_log_rolling.filePattern = ${sys:opensearch.logs.base_path}${sys:file.separator}${sys:opensearch.logs.cluster_name}_tracing-%i.trace.gz -appender.tracing_log_rolling.policies.type = Policies -appender.tracing_log_rolling.policies.size.type = SizeBasedTriggeringPolicy -appender.tracing_log_rolling.policies.size.size = 1GB -appender.tracing_log_rolling.strategy.type = DefaultRolloverStrategy -appender.tracing_log_rolling.strategy.max = 4 -################################################# -logger.tracing_log.name = tracing_log -logger.tracing_log.level = trace -logger.tracing_log.appenderRef.tracing_log_rolling.ref = tracing_log_rolling -logger.tracing_log.appenderRef.tracing_log_rolling_old.ref = tracing_log_rolling -logger.tracing_log.additivity = false diff --git a/libs/telemetry/build.gradle b/libs/telemetry/build.gradle index 98585ff80371e..ce94698836b4f 100644 --- a/libs/telemetry/build.gradle +++ b/libs/telemetry/build.gradle @@ -9,25 +9,6 @@ * GitHub history for details. */ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - dependencies { testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testImplementation "junit:junit:${versions.junit}" diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java new file mode 100644 index 0000000000000..a7c32082e54e2 --- /dev/null +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +/** + * Wrapper class to hold reference of Span + */ +public class SpanReference { + + private Span span; + + public SpanReference(Span span) { + this.span = span; + } + + public Span getSpan() { + return span; + } + + public void setSpan(Span span) { + this.span = span; + } +} diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java index b3ce260a8b9ee..1152e3aedfa88 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracingContextPropagator.java @@ -24,9 +24,11 @@ public interface TracingContextPropagator { Span extract(Map props); /** - * Injects tracing context in map - * @return consumer to add tracing context in map + * Injects tracing context + * + * @param currentSpan the current active span + * @param setter to add tracing context in map */ - BiConsumer, Map> inject(); + void inject(Span currentSpan, BiConsumer setter); } diff --git a/modules/telemetry-otel/build.gradle b/modules/telemetry-otel/build.gradle index a95f5f17baece..d4cf654f41b2a 100644 --- a/modules/telemetry-otel/build.gradle +++ b/modules/telemetry-otel/build.gradle @@ -25,6 +25,7 @@ dependencies { api "io.opentelemetry:opentelemetry-sdk-common:${versions.opentelemetry}" api "io.opentelemetry:opentelemetry-sdk-trace:${versions.opentelemetry}" api "io.opentelemetry:opentelemetry-sdk-metrics:${versions.opentelemetry}" + api "io.opentelemetry:opentelemetry-exporter-logging:${versions.opentelemetry}" api "io.opentelemetry:opentelemetry-semconv:${versions.opentelemetry}-alpha" api "io.opentelemetry:opentelemetry-sdk-logs:${versions.opentelemetry}-alpha" api "io.opentelemetry:opentelemetry-api-logs:${versions.opentelemetry}-alpha" @@ -46,6 +47,10 @@ thirdPartyAudit { 'io.opentelemetry.api.events.EventEmitterProvider', 'io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder', 'io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder', - 'io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer' + 'io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer', + 'io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties', + 'io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider', + 'io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider', + 'io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider' ) } diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 b/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 new file mode 100644 index 0000000000000..ef07e4cb81e34 --- /dev/null +++ b/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 @@ -0,0 +1 @@ +1b932170774da5e766440fa058d879f68fe2c5dd \ No newline at end of file diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt b/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt new file mode 100644 index 0000000000000..d645695673349 --- /dev/null +++ b/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt b/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java index cf441b87e3d13..e725453885b78 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; @@ -20,7 +21,6 @@ import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; import org.opensearch.common.settings.Settings; -import org.opensearch.telemetry.tracing.exporter.FileSpanExporter; import java.util.concurrent.TimeUnit; @@ -36,7 +36,7 @@ final class OTelResourceProvider { static OpenTelemetry get(Settings settings) { return get( settings, - new FileSpanExporter(), + new LoggingSpanExporter(), ContextPropagators.create(W3CTraceContextPropagator.getInstance()), Sampler.alwaysOn() ); diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java index fc48639f3c056..c60d1b87ab37b 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -32,30 +32,35 @@ public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin static final String OTEL_TRACER_NAME = "otel"; static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( - "telemetry.tracer.exporter.batch_size", + "telemetry.otel.tracer.exporter.batch_size", 512, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( - "telemetry.tracer.exporter.max_queue_size", + "telemetry.otel.tracer.exporter.max_queue_size", 2048, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( - "telemetry.tracer.exporter.delay", + "telemetry.otel.tracer.exporter.delay", TimeValue.timeValueSeconds(2), Setting.Property.NodeScope, Setting.Property.Dynamic ); + private final Settings settings; + /** - * No-args constructor + * Creates Otel plugin + * @param settings cluster settings */ - public OTelTelemetryModulePlugin() {} + public OTelTelemetryModulePlugin(Settings settings) { + this.settings = settings; + } @Override public List> getSettings() { @@ -74,8 +79,8 @@ public Settings additionalSettings() { } @Override - public Optional getTelemetry(Settings settings) { - return Optional.of(telemetry(settings)); + public Optional getTelemetry(TelemetrySettings settings) { + return Optional.of(telemetry()); } @Override @@ -83,7 +88,7 @@ public String getName() { return OTEL_TRACER_NAME; } - private Telemetry telemetry(Settings settings) { + private Telemetry telemetry() { return new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(settings)), new MetricsTelemetry() { }); } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java similarity index 72% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java rename to modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java index 90afe1278150c..5aa1069e60367 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/PropagatedSpan.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java @@ -11,13 +11,13 @@ /** * Propagated span through context propagation */ -public class PropagatedSpan extends OTelSpan { +public class OTelPropagatedSpan extends OTelSpan { /** - * Creates PropagatedSpan + * Creates OTelPropagatedSpan * @param span otel propagated span */ - public PropagatedSpan(io.opentelemetry.api.trace.Span span) { + public OTelPropagatedSpan(io.opentelemetry.api.trace.Span span) { super(null, span, null); } } diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java index 09947cb15f38e..445aac9fd946f 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java @@ -14,11 +14,8 @@ import io.opentelemetry.context.propagation.TextMapSetter; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; -import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; - /** * Otel implementation of TracingContextPropagator */ @@ -39,36 +36,24 @@ public Span extract(Map props) { Context context = openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), props, TEXT_MAP_GETTER); if (context != null) { io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.fromContext(context); - return new PropagatedSpan(span); + return new OTelPropagatedSpan(span); } return null; } @Override - public BiConsumer, Map> inject() { - return (requestHeaders, transientHeaders) -> { - if (transientHeaders != null && transientHeaders.containsKey(CURRENT_SPAN)) { - if (transientHeaders.get(CURRENT_SPAN) instanceof AtomicReference) { - @SuppressWarnings("unchecked") - AtomicReference currentSpanRef = (AtomicReference) transientHeaders.get(CURRENT_SPAN); - Span currentSpan = currentSpanRef.get(); - if (currentSpan instanceof OTelSpan) { - openTelemetry.getPropagators() - .getTextMapPropagator() - .inject(context((OTelSpan) currentSpan), requestHeaders, TEXT_MAP_SETTER); - } - } - } - }; + public void inject(Span currentSpan, BiConsumer setter) { + openTelemetry.getPropagators().getTextMapPropagator().inject(context((OTelSpan) currentSpan), setter, TEXT_MAP_SETTER); + } private static Context context(OTelSpan oTelSpan) { return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); } - private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { + private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { if (carrier != null) { - carrier.put(key, value); + carrier.accept(key, value); } }; diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java deleted file mode 100644 index 27f1aa05098de..0000000000000 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporter.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing.exporter; - -import io.opentelemetry.sdk.common.CompletableResultCode; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.trace.data.SpanData; -import io.opentelemetry.sdk.trace.export.SpanExporter; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * Writes the span to a log file. This is mostly for testing where you can trace one request and all your spans - * will be written to a file. Tracing log file would be available in the logs directory. - */ -public class FileSpanExporter implements SpanExporter { - static final String TRACING_LOG_PREFIX = "tracing_log"; - private static final Logger TRACING_LOGGER = LogManager.getLogger(TRACING_LOG_PREFIX); - private final Logger DEFAULT_LOGGER = LogManager.getLogger(FileSpanExporter.class); - private final String FIELD_SEPARATOR = "\t"; - - private final AtomicBoolean isShutdown = new AtomicBoolean(); - - /** - * No-args constructor - */ - public FileSpanExporter() {} - - @Override - public CompletableResultCode export(Collection spans) { - if (isShutdown.get()) { - return CompletableResultCode.ofFailure(); - } - StringBuilder sb = new StringBuilder(128); - for (SpanData span : spans) { - sb.setLength(0); - InstrumentationScopeInfo instrumentationScopeInfo = span.getInstrumentationScopeInfo(); - sb.append("'") - .append(span.getName()) - .append("'") - .append(FIELD_SEPARATOR) - .append(span.getTraceId()) - .append(FIELD_SEPARATOR) - .append(span.getSpanId()) - .append(FIELD_SEPARATOR) - .append(span.getParentSpanId()) - .append(FIELD_SEPARATOR) - .append(span.getKind()) - .append(FIELD_SEPARATOR) - .append(span.getStartEpochNanos()) - .append(FIELD_SEPARATOR) - .append(span.getEndEpochNanos()) - .append(FIELD_SEPARATOR) - .append("[tracer:") - .append(instrumentationScopeInfo.getName()) - .append(":") - .append(instrumentationScopeInfo.getVersion() == null ? "" : instrumentationScopeInfo.getVersion()) - .append("]") - .append(FIELD_SEPARATOR) - .append(span.getAttributes()); - TRACING_LOGGER.info(sb.toString()); - } - return CompletableResultCode.ofSuccess(); - } - - @Override - public CompletableResultCode flush() { - return CompletableResultCode.ofSuccess(); - } - - @Override - public CompletableResultCode shutdown() { - if (!isShutdown.compareAndSet(false, true)) { - DEFAULT_LOGGER.info("Duplicate shutdown() calls."); - } - return CompletableResultCode.ofSuccess(); - } -} diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java b/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java deleted file mode 100644 index 6da39e9202ca3..0000000000000 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/exporter/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/** - * Contains span exporters - */ -package org.opensearch.telemetry.tracing.exporter; diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java index a36e228cecde9..a4d7212dd62ae 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -29,7 +29,7 @@ public class OTelTelemetryModulePluginTests extends OpenSearchTestCase { @SuppressForbidden(reason = "manipulates system properties for testing") public void testAdditionalSettingWithTracingFeatureDisabled() { System.setProperty("opensearch.experimental.feature.telemetry.enabled", "false"); - Settings settings = new OTelTelemetryModulePlugin().additionalSettings(); + Settings settings = new OTelTelemetryModulePlugin(null).additionalSettings(); assertTrue(settings.isEmpty()); } @@ -37,7 +37,7 @@ public void testAdditionalSettingWithTracingFeatureDisabled() { @SuppressForbidden(reason = "manipulates system properties for testing") public void testAdditionalSettingWithTracingFeatureEnabled() { System.setProperty("opensearch.experimental.feature.telemetry.enabled", "true"); - Settings settings = new OTelTelemetryModulePlugin().additionalSettings(); + Settings settings = new OTelTelemetryModulePlugin(null).additionalSettings(); assertFalse(settings.isEmpty()); } @@ -46,8 +46,8 @@ public void testGetTelemetry() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); Settings settings = Settings.builder().build(); - OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(); - Optional tracer = oTelTracerModulePlugin.getTelemetry(settings); + OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(settings); + Optional tracer = oTelTracerModulePlugin.getTelemetry(null); assertEquals(OTEL_TRACER_NAME, oTelTracerModulePlugin.getName()); TracingTelemetry tracingTelemetry = tracer.get().getTracingTelemetry(); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java index 2f7a5474c808e..dc8c66553a7d8 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java @@ -19,11 +19,9 @@ import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; public class OtelTracingContextPropagatorTests extends OpenSearchTestCase { @@ -34,14 +32,12 @@ public void testAddTracerContextToHeader() { Span mockSpan = mock(Span.class); when(mockSpan.getSpanContext()).thenReturn(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); OTelSpan span = new OTelSpan("spanName", mockSpan, null); - AtomicReference spanHolder = new AtomicReference<>(span); - Map transientHeaders = Map.of(CURRENT_SPAN, spanHolder); Map requestHeaders = new HashMap<>(); OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); - tracingContextPropagator.inject().accept(requestHeaders, transientHeaders); + tracingContextPropagator.inject(span, (key, value) -> requestHeaders.put(key, value)); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); } diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java deleted file mode 100644 index bfea5a24019ba..0000000000000 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/FileSpanExporterTests.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing.exporter; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.sdk.common.CompletableResultCode; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.internal.AttributesMap; -import io.opentelemetry.sdk.trace.data.SpanData; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.mockito.Mockito; -import org.opensearch.common.logging.Loggers; -import org.opensearch.test.OpenSearchTestCase; - -import java.util.Arrays; -import java.util.Locale; - -public class FileSpanExporterTests extends OpenSearchTestCase { - private static MockAppender appender; - private static Logger testLogger1 = LogManager.getLogger(FileSpanExporter.TRACING_LOG_PREFIX); - - @BeforeClass - public static void init() throws IllegalAccessException { - appender = new MockAppender("trace_appender"); - appender.start(); - Loggers.addAppender(testLogger1, appender); - } - - @AfterClass - public static void cleanup() { - Loggers.removeAppender(testLogger1, appender); - appender.stop(); - } - - private final FileSpanExporter spanExporter = new FileSpanExporter(); - - public void testOutputFormat() { - String name = "TestSpan"; - String traceId = "6b44b6eadda4535388c406d3ba8894d4"; - String spanId = "96a0878e2febe8ba"; - String parentSpanId = "72a0878e2febg8fc"; - SpanData mockedSpanData = Mockito.mock(SpanData.class); - Mockito.when(mockedSpanData.getName()).thenReturn(name); - Mockito.when(mockedSpanData.getTraceId()).thenReturn(traceId); - Mockito.when(mockedSpanData.getSpanId()).thenReturn(spanId); - Mockito.when(mockedSpanData.getParentSpanId()).thenReturn(parentSpanId); - Mockito.when(mockedSpanData.getKind()).thenReturn(SpanKind.INTERNAL); - Mockito.when(mockedSpanData.getInstrumentationScopeInfo()) - .thenReturn(InstrumentationScopeInfo.create("instrumentation-library-name", "1.0.0", null)); - - AttributesMap attributesMap = AttributesMap.create(128, 128); - attributesMap.put(AttributeKey.stringKey("SpanId"), spanId); - - Mockito.when(mockedSpanData.getAttributes()).thenReturn(attributesMap); - - spanExporter.export(Arrays.asList(mockedSpanData)); - String logData = appender.getLastEventAndReset().getMessage().getFormattedMessage(); - assertEquals(getExpectedLogMessage(name, traceId, spanId, parentSpanId, attributesMap), logData); - assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush()); - assertEquals(CompletableResultCode.ofSuccess(), spanExporter.shutdown()); - - spanExporter.export(Arrays.asList(mockedSpanData)); - assertNull(appender.getLastEventAndReset()); - } - - private String getExpectedLogMessage(String name, String traceId, String spanId, String parentSpanId, AttributesMap attributesMap) { - return String.format( - Locale.ROOT, - "'%s'\t%s\t%s\t%s\t%s\t%d\t%d\t[%s:%s:%s]\t%s", - name, - traceId, - spanId, - parentSpanId, - "INTERNAL", - 0, - 0, - "tracer", - "instrumentation-library-name", - "1.0.0", - attributesMap - ); - } - -} diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java b/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java deleted file mode 100644 index b96c2074615e1..0000000000000 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/exporter/MockAppender.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing.exporter; - -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AbstractAppender; -import org.apache.logging.log4j.core.filter.RegexFilter; -import org.apache.logging.log4j.message.ParameterizedMessage; - -public class MockAppender extends AbstractAppender { - public LogEvent lastEvent; - - public MockAppender(final String name) throws IllegalAccessException { - super(name, RegexFilter.createFilter(".*(\n.*)*", new String[0], false, null, null), null); - } - - @Override - public void append(LogEvent event) { - lastEvent = event.toImmutable(); - } - - ParameterizedMessage lastParameterizedMessage() { - return (ParameterizedMessage) lastEvent.getMessage(); - } - - public LogEvent getLastEventAndReset() { - LogEvent toReturn = lastEvent; - lastEvent = null; - return toReturn; - } -} diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 185240fbc0183..40c28d9463c92 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -44,8 +44,9 @@ import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; import org.opensearch.http.HttpTransportSettings; -import org.opensearch.telemetry.tracing.TracerManager; +import org.opensearch.telemetry.tracing.SpanReference; import org.opensearch.tasks.Task; +import org.opensearch.telemetry.tracing.TracerFactory; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -58,7 +59,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; import java.util.function.Function; @@ -157,7 +157,7 @@ public StoredContext stashContext() { if (context.transientHeaders.containsKey(CURRENT_SPAN)) { threadContextStruct = threadContextStruct.putTransient( CURRENT_SPAN, - new AtomicReference<>(((AtomicReference) context.transientHeaders.get(CURRENT_SPAN)).get()) + new SpanReference(((SpanReference) context.transientHeaders.get(CURRENT_SPAN)).getSpan()) ); } @@ -260,7 +260,7 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collectio if (newContext.transientHeaders.containsKey(CURRENT_SPAN)) { newContext.transientHeaders.put( CURRENT_SPAN, - new AtomicReference<>(((AtomicReference) newContext.transientHeaders.get(CURRENT_SPAN)).get()) + new SpanReference(((SpanReference) newContext.transientHeaders.get(CURRENT_SPAN)).getSpan()) ); } @@ -728,8 +728,12 @@ private ThreadContextStruct copyHeaders(Iterable> head } private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { - TracerManager.getTracerHeaderInjector().accept(this.requestHeaders, this.transientHeaders); - + if (transientHeaders.containsKey(CURRENT_SPAN)) { + TracerFactory.propagator.inject( + ((SpanReference) transientHeaders.get(CURRENT_SPAN)).getSpan(), + (key, value) -> requestHeaders.put(key, value) + ); + } final Map requestHeaders; if (defaultHeaders.isEmpty()) { requestHeaders = this.requestHeaders; diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index c03dcb3df1cc8..78c1c127f1e65 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -56,7 +56,8 @@ import org.opensearch.monitor.fs.FsProbe; import org.opensearch.plugins.ExtensionAwarePlugin; import org.opensearch.plugins.SearchPipelinePlugin; -import org.opensearch.telemetry.tracing.TracerManager; +import org.opensearch.telemetry.tracing.NoopTracerFactory; +import org.opensearch.telemetry.tracing.TracerFactory; import org.opensearch.search.backpressure.SearchBackpressureService; import org.opensearch.search.backpressure.settings.SearchBackpressureSettings; import org.opensearch.search.pipeline.SearchPipelineService; @@ -378,6 +379,7 @@ public static class DiscoverySettings { private final Collection pluginLifecycleComponents; private final LocalNodeFactory localNodeFactory; private final NodeService nodeService; + private final TracerFactory tracerFactory; final NamedWriteableRegistry namedWriteableRegistry; private final AtomicReference runnableTaskListener; private FileCache fileCache; @@ -1029,9 +1031,11 @@ protected Node( final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings()); List telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class); TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); - TracerManager.initTracerManager(telemetrySettings, telemetryModule.getTelemetry(), threadPool); - resourcesToClose.add(TracerManager::closeTracer); + tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool); + } else { + tracerFactory = new NoopTracerFactory(); } + resourcesToClose.add(tracerFactory::close); final List> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class) .stream() @@ -1138,6 +1142,7 @@ protected Node( b.bind(FsHealthService.class).toInstance(fsHealthService); b.bind(SystemIndices.class).toInstance(systemIndices); b.bind(IdentityService.class).toInstance(identityService); + b.bind(TracerFactory.class).toInstance(this.tracerFactory); }); injector = modules.createInjector(); @@ -1495,7 +1500,7 @@ public synchronized void close() throws IOException { toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(stopWatch::stop); if (FeatureFlags.isEnabled(TELEMETRY)) { - toClose.add(TracerManager::closeTracer); + toClose.add(() -> injector.getInstance(TracerFactory.class)); } if (logger.isTraceEnabled()) { diff --git a/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java index e133a7d5a3a17..33dc9b7a0c843 100644 --- a/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/TelemetryPlugin.java @@ -8,8 +8,8 @@ package org.opensearch.plugins; -import org.opensearch.common.settings.Settings; import org.opensearch.telemetry.Telemetry; +import org.opensearch.telemetry.TelemetrySettings; import java.util.Optional; @@ -18,7 +18,7 @@ */ public interface TelemetryPlugin { - Optional getTelemetry(Settings settings); + Optional getTelemetry(TelemetrySettings settings); String getName(); diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java index 2b2e5320f1836..78e2a1df197a3 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java @@ -38,7 +38,7 @@ public TelemetryModule(Settings settings, List telemetryPlugins this.settings = settings; for (TelemetryPlugin telemetryPlugin : telemetryPlugins) { - Optional telemetry = telemetryPlugin.getTelemetry(settings); + Optional telemetry = telemetryPlugin.getTelemetry(telemetrySettings); if (telemetry.isPresent()) { registerTelemetry(telemetryPlugin.getName(), telemetry.get()); } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java new file mode 100644 index 0000000000000..9b158307c2371 --- /dev/null +++ b/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.telemetry.tracing; + +import org.opensearch.telemetry.tracing.noop.NoopTracer; + +/** + * No-op implementation of TracerFactory + */ +public class NoopTracerFactory extends TracerFactory { + public NoopTracerFactory() { + super(null, null, null); + } + + @Override + public Tracer getTracer() { + return NoopTracer.INSTANCE; + } + + @Override + public void close() { + + } + +} diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java index 63cde05f56cbb..87307085236dd 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java @@ -11,7 +11,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; /** * Core's ThreadContext based TracerContextStorage implementation @@ -37,11 +36,11 @@ public void put(String key, Span span) { if (span == null) { return; } - AtomicReference currentSpanRef = threadContext.getTransient(key); + SpanReference currentSpanRef = threadContext.getTransient(key); if (currentSpanRef == null) { - threadContext.putTransient(key, new AtomicReference<>(span)); + threadContext.putTransient(key, new SpanReference(span)); } else { - currentSpanRef.set(span); + currentSpanRef.setSpan(span); } } @@ -51,8 +50,8 @@ Span getCurrentSpan(String key) { } private Optional spanFromThreadContext(String key) { - AtomicReference currentSpanRef = threadContext.getTransient(key); - return (currentSpanRef == null) ? Optional.empty() : Optional.ofNullable(currentSpanRef.get()); + SpanReference currentSpanRef = threadContext.getTransient(key); + return (currentSpanRef == null) ? Optional.empty() : Optional.ofNullable(currentSpanRef.getSpan()); } private Span spanFromHeader() { diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java similarity index 57% rename from server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java rename to server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java index 57a1a55214cd8..95842082f20ed 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerManager.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java @@ -15,9 +15,8 @@ import org.opensearch.telemetry.tracing.noop.NoopTracer; import org.opensearch.threadpool.ThreadPool; +import java.io.Closeable; import java.io.IOException; -import java.util.Map; -import java.util.function.BiConsumer; /** * TracerManager represents a single global class that is used to access tracers. @@ -25,10 +24,9 @@ * The Tracer singleton object can be retrieved using TracerManager.getTracer(). The TracerManager object * is created during class initialization and cannot subsequently be changed. */ -public class TracerManager { +public class TracerFactory implements Closeable { - private static final Logger logger = LogManager.getLogger(TracerManager.class); - private static volatile TracerManager INSTANCE; + private static final Logger logger = LogManager.getLogger(TracerFactory.class); private volatile Tracer defaultTracer; private final Object mutex = new Object(); @@ -36,60 +34,40 @@ public class TracerManager { private final Telemetry telemetry; private final ThreadPool threadPool; - /** - * Initializes the TracerFactory singleton instance - * - * @param telemetrySettings tracer settings instance - * @param telemetry telemetry instance - * @param threadPool thread pool instance - */ - public static synchronized void initTracerManager(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { - if (INSTANCE == null) { - INSTANCE = new TracerManager(telemetrySettings, telemetry, threadPool); - } else { - logger.warn("Trying to double initialize TracerFactory, skipping"); + // TODO Hack, fix me + public static TracingContextPropagator propagator; + + public TracerFactory(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { + this.telemetrySettings = telemetrySettings; + this.telemetry = telemetry; + this.threadPool = threadPool; + if (telemetry != null) { + propagator = telemetry.getTracingTelemetry().getContextPropagator(); } } /** - * Returns the {@link Tracer} singleton instance - * @return Tracer instance + * Returns the tracer instance + * @return tracer instance */ - public static Tracer getTracer() { - return INSTANCE == null ? NoopTracer.INSTANCE : INSTANCE.tracer(); - } - - public static BiConsumer, Map> getTracerHeaderInjector() { - return INSTANCE == null ? (x, y) -> {} : INSTANCE.tracerHeaderInjector(); + public Tracer getTracer() { + return isTracingDisabled() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); } /** * Closes the {@link Tracer} */ - public static void closeTracer() { - if (INSTANCE != null && INSTANCE.defaultTracer != null) { + @Override + public void close() { + if (defaultTracer != null) { try { - INSTANCE.defaultTracer.close(); + defaultTracer.close(); } catch (IOException e) { logger.warn("Error closing tracer", e); } } } - public TracerManager(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { - this.telemetrySettings = telemetrySettings; - this.telemetry = telemetry; - this.threadPool = threadPool; - } - - private Tracer tracer() { - return isTracingDisabled() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); - } - - private BiConsumer, Map> tracerHeaderInjector() { - return isTracingDisabled() ? (x, y) -> {} : telemetry.getTracingTelemetry().getContextPropagator().inject(); - } - private boolean isTracingDisabled() { return !telemetrySettings.isTracingEnabled(); } @@ -98,7 +76,7 @@ private Tracer getOrCreateDefaultTracerInstance() { if (defaultTracer == null) { synchronized (mutex) { if (defaultTracer == null) { - logger.info("Creating Otel tracer..."); + logger.info("Creating default tracer..."); TracingTelemetry tracingTelemetry = telemetry.getTracingTelemetry(); TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( threadPool.getThreadContext(), @@ -111,9 +89,4 @@ private Tracer getOrCreateDefaultTracerInstance() { return defaultTracer; } - // for testing - static void clear() { - INSTANCE = null; - } - } diff --git a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java index 296e9a380a904..7847289d228c5 100644 --- a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java +++ b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java @@ -33,7 +33,7 @@ public void testGetTelemetryDefault() { TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry1; @@ -60,7 +60,7 @@ public void testGetTelemetryCustom() { TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry1; @@ -72,7 +72,7 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry2; @@ -101,7 +101,7 @@ public void testGetTelemetryWithMoreThanOneCustomTelemetry() { TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); TracingTelemetry tracingTelemetry3 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry1; @@ -113,7 +113,7 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry2; @@ -125,7 +125,7 @@ public MetricsTelemetry getMetricsTelemetry() { } })); when(telemetryPlugin2.getName()).thenReturn("foo"); - when(telemetryPlugin3.getTelemetry(settings)).thenReturn(Optional.of(new Telemetry() { + when(telemetryPlugin3.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { @Override public TracingTelemetry getTracingTelemetry() { return tracingTelemetry3; diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java similarity index 76% rename from server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java rename to server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java index d70135027b3ba..1e3ed1adaa0f4 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerManagerTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java @@ -9,7 +9,6 @@ package org.opensearch.telemetry.tracing; import org.junit.After; -import org.junit.Before; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; @@ -27,29 +26,21 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class TracerManagerTests extends OpenSearchTestCase { +public class TracerFactoryTests extends OpenSearchTestCase { - @Before - public void setup() { - TracerManager.clear(); - } + private TracerFactory tracerFactory; @After public void close() { - TracerManager.closeTracer(); - } - - public void testGetTracerWithUninitializedTracerFactory() { - Tracer tracer = TracerManager.getTracer(); - assertTrue(tracer instanceof NoopTracer); + tracerFactory.close(); } public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Settings settings = Settings.builder().put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), false).build(); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); - TracerManager.initTracerManager(telemetrySettings, null, mock(ThreadPool.class)); + tracerFactory = new TracerFactory(telemetrySettings, null, mock(ThreadPool.class)); - Tracer tracer = TracerManager.getTracer(); + Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof NoopTracer); } @@ -58,9 +49,9 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); Telemetry mockTelemetry = mock(Telemetry.class); when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); - TracerManager.initTracerManager(telemetrySettings, mockTelemetry, mock(ThreadPool.class)); + tracerFactory = new TracerFactory(telemetrySettings, mockTelemetry, mock(ThreadPool.class)); - Tracer tracer = TracerManager.getTracer(); + Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof DefaultTracer); } From 85950585cacf8d9260a051d8389fd5c67bb5e547 Mon Sep 17 00:00:00 2001 From: suranjay Date: Sat, 24 Jun 2023 17:15:45 +0530 Subject: [PATCH 27/38] move otel to plugin Signed-off-by: suranjay --- .../telemetry-otel/build.gradle | 0 .../opentelemetry-api-1.26.0.jar.sha1 | 0 .../licenses/opentelemetry-api-LICENSE.txt | 0 .../licenses/opentelemetry-api-NOTICE.txt | 0 ...entelemetry-api-logs-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-api-logs-LICENSE.txt | 0 .../opentelemetry-api-logs-NOTICE.txt | 0 .../opentelemetry-context-1.26.0.jar.sha1 | 0 .../opentelemetry-context-LICENSE.txt | 0 .../licenses/opentelemetry-context-NOTICE.txt | 0 ...telemetry-exporter-logging-1.26.0.jar.sha1 | 0 ...opentelemetry-exporter-logging-LICENSE.txt | 0 .../opentelemetry-exporter-logging-NOTICE.txt | 0 .../opentelemetry-sdk-1.26.0.jar.sha1 | 0 .../licenses/opentelemetry-sdk-LICENSE.txt | 0 .../licenses/opentelemetry-sdk-NOTICE.txt | 0 .../opentelemetry-sdk-common-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-common-LICENSE.txt | 0 .../opentelemetry-sdk-common-NOTICE.txt | 0 ...entelemetry-sdk-logs-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-sdk-logs-LICENSE.txt | 0 .../opentelemetry-sdk-logs-NOTICE.txt | 0 .../opentelemetry-sdk-metrics-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-metrics-LICENSE.txt | 0 .../opentelemetry-sdk-metrics-NOTICE.txt | 0 .../opentelemetry-sdk-trace-1.26.0.jar.sha1 | 0 .../opentelemetry-sdk-trace-LICENSE.txt | 0 .../opentelemetry-sdk-trace-NOTICE.txt | 0 ...pentelemetry-semconv-1.26.0-alpha.jar.sha1 | 0 .../opentelemetry-semconv-LICENSE.txt | 0 .../licenses/opentelemetry-semconv-NOTICE.txt | 0 .../telemetry/OTelTelemetryModulePlugin.java | 30 ++-- .../opensearch/telemetry/package-info.java | 0 .../telemetry/tracing/OTelPropagatedSpan.java | 0 .../tracing}/OTelResourceProvider.java | 8 +- .../telemetry/tracing/OTelSpan.java | 0 .../telemetry/tracing/OtelTelemetryImpl.java | 0 .../tracing/OtelTracingContextPropagator.java | 0 .../tracing/OtelTracingTelemetry.java | 0 .../telemetry/tracing/package-info.java | 0 .../plugin-metadata/plugin-security.policy | 0 .../OTelTelemetryModulePluginTests.java | 17 --- .../telemetry/tracing/OTelSpanTests.java | 0 .../OtelTracingContextPropagatorTests.java | 0 .../tracing/OtelTracingTelemetryTests.java | 0 .../common/settings/ClusterSettings.java | 3 +- .../main/java/org/opensearch/node/Node.java | 2 +- .../opensearch/telemetry/TelemetryModule.java | 45 ++---- .../telemetry/tracing/TracerFactory.java | 15 +- .../telemetry/TelemetryModuleTests.java | 141 ++++-------------- .../telemetry/tracing/TracerFactoryTests.java | 3 +- 51 files changed, 67 insertions(+), 197 deletions(-) rename {modules => plugins}/telemetry-otel/build.gradle (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt (100%) rename {modules => plugins}/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java (74%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java (100%) rename {modules/telemetry-otel/src/main/java/org/opensearch/telemetry => plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing}/OTelResourceProvider.java (89%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java (100%) rename {modules => plugins}/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java (100%) rename {modules => plugins}/telemetry-otel/src/main/plugin-metadata/plugin-security.policy (100%) rename {modules => plugins}/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java (67%) rename {modules => plugins}/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java (100%) rename {modules => plugins}/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java (100%) rename {modules => plugins}/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java (100%) diff --git a/modules/telemetry-otel/build.gradle b/plugins/telemetry-otel/build.gradle similarity index 100% rename from modules/telemetry-otel/build.gradle rename to plugins/telemetry-otel/build.gradle diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-api-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-api-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-api-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-api-logs-1.26.0-alpha.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-api-logs-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-api-logs-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-context-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-context-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-context-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-exporter-logging-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-common-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-common-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-common-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-1.26.0-alpha.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-logs-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-metrics-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-1.26.0.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-sdk-trace-NOTICE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 b/plugins/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 rename to plugins/telemetry-otel/licenses/opentelemetry-semconv-1.26.0-alpha.jar.sha1 diff --git a/modules/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt b/plugins/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-semconv-LICENSE.txt diff --git a/modules/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt b/plugins/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt similarity index 100% rename from modules/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt rename to plugins/telemetry-otel/licenses/opentelemetry-semconv-NOTICE.txt diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java similarity index 74% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java index c60d1b87ab37b..098cade87cac5 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -11,10 +11,10 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.TelemetryPlugin; import org.opensearch.telemetry.metrics.MetricsTelemetry; +import org.opensearch.telemetry.tracing.OTelResourceProvider; import org.opensearch.telemetry.tracing.OtelTelemetryImpl; import org.opensearch.telemetry.tracing.OtelTracingTelemetry; @@ -22,8 +22,6 @@ import java.util.List; import java.util.Optional; -import static org.opensearch.common.util.FeatureFlags.TELEMETRY; - /** * Telemetry plugin based on Otel */ @@ -31,21 +29,30 @@ public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin static final String OTEL_TRACER_NAME = "otel"; - static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( + /** + * span exporter batch size + */ + public static final Setting TRACER_EXPORTER_BATCH_SIZE_SETTING = Setting.intSetting( "telemetry.otel.tracer.exporter.batch_size", 512, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); - static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( + /** + * span exporter max queue size + */ + public static final Setting TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING = Setting.intSetting( "telemetry.otel.tracer.exporter.max_queue_size", 2048, 1, Setting.Property.NodeScope, Setting.Property.Dynamic ); - static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( + /** + * span exporter delay in seconds + */ + public static final Setting TRACER_EXPORTER_DELAY_SETTING = Setting.timeSetting( "telemetry.otel.tracer.exporter.delay", TimeValue.timeValueSeconds(2), Setting.Property.NodeScope, @@ -67,17 +74,6 @@ public List> getSettings() { return Arrays.asList(TRACER_EXPORTER_BATCH_SIZE_SETTING, TRACER_EXPORTER_DELAY_SETTING, TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING); } - @Override - public Settings additionalSettings() { - if (FeatureFlags.isEnabled(TELEMETRY)) { - return Settings.builder() - // set Otel tracer as default telemetry provider - .put(TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME) - .build(); - } - return Settings.EMPTY; - } - @Override public Optional getTelemetry(TelemetrySettings settings) { return Optional.of(telemetry()); diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/package-info.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelPropagatedSpan.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java similarity index 89% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java index e725453885b78..6f5ced4e9348f 100644 --- a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelResourceProvider.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.telemetry; +package org.opensearch.telemetry.tracing; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.Attributes; @@ -31,9 +31,9 @@ /** * This class encapsulates all OpenTelemetry related resources */ -final class OTelResourceProvider { +public final class OTelResourceProvider { - static OpenTelemetry get(Settings settings) { + public static OpenTelemetry get(Settings settings) { return get( settings, new LoggingSpanExporter(), @@ -42,7 +42,7 @@ static OpenTelemetry get(Settings settings) { ); } - static OpenTelemetry get(Settings settings, SpanExporter spanExporter, ContextPropagators contextPropagators, Sampler sampler) { + public static OpenTelemetry get(Settings settings, SpanExporter spanExporter, ContextPropagators contextPropagators, Sampler sampler) { Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor(spanProcessor(settings, spanExporter)) diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java diff --git a/modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java similarity index 100% rename from modules/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/package-info.java diff --git a/modules/telemetry-otel/src/main/plugin-metadata/plugin-security.policy b/plugins/telemetry-otel/src/main/plugin-metadata/plugin-security.policy similarity index 100% rename from modules/telemetry-otel/src/main/plugin-metadata/plugin-security.policy rename to plugins/telemetry-otel/src/main/plugin-metadata/plugin-security.policy diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java similarity index 67% rename from modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java index a4d7212dd62ae..8391933fa5d87 100644 --- a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -8,7 +8,6 @@ package org.opensearch.telemetry; -import org.opensearch.common.SuppressForbidden; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; @@ -26,22 +25,6 @@ public class OTelTelemetryModulePluginTests extends OpenSearchTestCase { - @SuppressForbidden(reason = "manipulates system properties for testing") - public void testAdditionalSettingWithTracingFeatureDisabled() { - System.setProperty("opensearch.experimental.feature.telemetry.enabled", "false"); - Settings settings = new OTelTelemetryModulePlugin(null).additionalSettings(); - - assertTrue(settings.isEmpty()); - } - - @SuppressForbidden(reason = "manipulates system properties for testing") - public void testAdditionalSettingWithTracingFeatureEnabled() { - System.setProperty("opensearch.experimental.feature.telemetry.enabled", "true"); - Settings settings = new OTelTelemetryModulePlugin(null).additionalSettings(); - - assertFalse(settings.isEmpty()); - } - public void testGetTelemetry() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java similarity index 100% rename from modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelSpanTests.java diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java similarity index 100% rename from modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java diff --git a/modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java similarity index 100% rename from modules/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index 76bfba1e85618..d70ea16cf5fdd 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -52,7 +52,6 @@ import org.opensearch.tasks.TaskManager; import org.opensearch.tasks.TaskResourceTrackingService; import org.opensearch.tasks.consumer.TopNSearchTasksLogger; -import org.opensearch.telemetry.TelemetryModule; import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.watcher.ResourceWatcherService; import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; @@ -679,6 +678,6 @@ public void apply(Settings value, Settings current, Settings previous) { List.of(FeatureFlags.CONCURRENT_SEGMENT_SEARCH), List.of(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING), List.of(FeatureFlags.TELEMETRY), - List.of(TelemetrySettings.TRACER_ENABLED_SETTING, TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING) + List.of(TelemetrySettings.TRACER_ENABLED_SETTING) ); } diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index 78c1c127f1e65..9a8729683d42b 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -1030,7 +1030,7 @@ protected Node( if (FeatureFlags.isEnabled(TELEMETRY)) { final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings()); List telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class); - TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, telemetrySettings); tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool); } else { tracerFactory = new NoopTracerFactory(); diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java index 78e2a1df197a3..9224a180ab894 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java @@ -8,13 +8,9 @@ package org.opensearch.telemetry; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; import org.opensearch.plugins.TelemetryPlugin; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; /** @@ -24,47 +20,32 @@ */ public class TelemetryModule { - private static final String TELEMETRY_TYPE_DEFAULT = "telemetry.type.default"; + private Telemetry telemetry; - public static final Setting TELEMETRY_DEFAULT_TYPE_SETTING = Setting.simpleString( - TELEMETRY_TYPE_DEFAULT, - Setting.Property.NodeScope - ); - - private final Settings settings; - private final Map telemetryFactories = new HashMap<>(); - - public TelemetryModule(Settings settings, List telemetryPlugins, TelemetrySettings telemetrySettings) { - this.settings = settings; + public TelemetryModule(List telemetryPlugins, TelemetrySettings telemetrySettings) { for (TelemetryPlugin telemetryPlugin : telemetryPlugins) { Optional telemetry = telemetryPlugin.getTelemetry(telemetrySettings); if (telemetry.isPresent()) { - registerTelemetry(telemetryPlugin.getName(), telemetry.get()); + registerTelemetry(telemetry.get()); } } } - public Telemetry getTelemetry() { + public Optional getTelemetry() { // if only default(Otel) telemetry is registered, return it - if (telemetryFactories.size() == 1) { - return telemetryFactories.values().stream().findFirst().get(); + if (telemetry != null) { + return Optional.of(telemetry); + } else { + return Optional.empty(); } - // if custom telemetry is also registered, return custom telemetry - return telemetryFactories.entrySet() - .stream() - .filter(entry -> !entry.getValue().equals(TELEMETRY_DEFAULT_TYPE_SETTING.get(settings))) - .map(entry -> entry.getValue()) - .findFirst() - .get(); } - private void registerTelemetry(String key, Telemetry factory) { - if (telemetryFactories.putIfAbsent(key, factory) != null) { - throw new IllegalArgumentException("telemetry for name: " + key + " is already registered"); - } - if (telemetryFactories.size() == 3) { - throw new IllegalArgumentException("Cannot register more than one custom telemetry"); + private void registerTelemetry(Telemetry factory) { + if (telemetry == null) { + telemetry = factory; + } else { + throw new IllegalArgumentException("Cannot register more than one telemetry"); } } diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java index 95842082f20ed..69a2d051ee3a3 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java @@ -17,11 +17,12 @@ import java.io.Closeable; import java.io.IOException; +import java.util.Optional; /** * TracerManager represents a single global class that is used to access tracers. * - * The Tracer singleton object can be retrieved using TracerManager.getTracer(). The TracerManager object + * The Tracer singleton object can be retrieved using tracerManager.getTracer(). The TracerManager object * is created during class initialization and cannot subsequently be changed. */ public class TracerFactory implements Closeable { @@ -31,18 +32,18 @@ public class TracerFactory implements Closeable { private volatile Tracer defaultTracer; private final Object mutex = new Object(); private final TelemetrySettings telemetrySettings; - private final Telemetry telemetry; + private final Optional telemetry; private final ThreadPool threadPool; // TODO Hack, fix me public static TracingContextPropagator propagator; - public TracerFactory(TelemetrySettings telemetrySettings, Telemetry telemetry, ThreadPool threadPool) { + public TracerFactory(TelemetrySettings telemetrySettings, Optional telemetry, ThreadPool threadPool) { this.telemetrySettings = telemetrySettings; this.telemetry = telemetry; this.threadPool = threadPool; - if (telemetry != null) { - propagator = telemetry.getTracingTelemetry().getContextPropagator(); + if (telemetry != null && telemetry.isPresent()) { + propagator = telemetry.get().getTracingTelemetry().getContextPropagator(); } } @@ -51,7 +52,7 @@ public TracerFactory(TelemetrySettings telemetrySettings, Telemetry telemetry, T * @return tracer instance */ public Tracer getTracer() { - return isTracingDisabled() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); + return isTracingDisabled() || !telemetry.isPresent() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); } /** @@ -77,7 +78,7 @@ private Tracer getOrCreateDefaultTracerInstance() { synchronized (mutex) { if (defaultTracer == null) { logger.info("Creating default tracer..."); - TracingTelemetry tracingTelemetry = telemetry.getTracingTelemetry(); + TracingTelemetry tracingTelemetry = telemetry.get().getTracingTelemetry(); TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( threadPool.getThreadContext(), tracingTelemetry diff --git a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java index 7847289d228c5..45344ab4253f7 100644 --- a/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java +++ b/server/src/test/java/org/opensearch/telemetry/TelemetryModuleTests.java @@ -8,149 +8,58 @@ package org.opensearch.telemetry; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.plugins.TelemetryPlugin; -import org.opensearch.telemetry.metrics.MetricsTelemetry; -import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; -import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.Set; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.telemetry.TelemetryModule.TELEMETRY_DEFAULT_TYPE_SETTING; public class TelemetryModuleTests extends OpenSearchTestCase { - public void testGetTelemetryDefault() { - Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); - TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); - TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); - TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry1; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(telemetryPlugin1.getName()).thenReturn("otel"); - List telemetryPlugins = List.of(telemetryPlugin1); + public void testGetTelemetrySuccess() { + TelemetryPlugin telemetryPlugin = mock(TelemetryPlugin.class); + when(telemetryPlugin.getName()).thenReturn("otel"); + Telemetry mockTelemetry = mock(Telemetry.class); + when(telemetryPlugin.getTelemetry(any())).thenReturn(Optional.of(mockTelemetry)); + List telemetryPlugins = List.of(telemetryPlugin); - TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, any()); - assertEquals(tracingTelemetry1, telemetryModule.getTelemetry().getTracingTelemetry()); + assertTrue(telemetryModule.getTelemetry().isPresent()); + assertEquals(mockTelemetry, telemetryModule.getTelemetry().get()); } - public void testGetTelemetryCustom() { - Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); - Set> clusterSettings = getClusterSettings(); - TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, clusterSettings)); + public void testGetTelemetryWithMultipleInstalledPlugins() { TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); - TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); - TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry1; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry2; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(telemetryPlugin2.getName()).thenReturn("foo"); - List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2); + Telemetry mockTelemetry1 = mock(Telemetry.class); + Telemetry mockTelemetry2 = mock(Telemetry.class); - TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + when(telemetryPlugin1.getTelemetry(any())).thenReturn(Optional.of(mockTelemetry1)); + when(telemetryPlugin2.getTelemetry(any())).thenReturn(Optional.of(mockTelemetry2)); - assertEquals(tracingTelemetry2, telemetryModule.getTelemetry().getTracingTelemetry()); - } + List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2); - public void testGetTelemetryWithMoreThanOneCustomTelemetry() { - Settings settings = Settings.builder().put(TELEMETRY_DEFAULT_TYPE_SETTING.getKey(), "otel").build(); - Set> clusterSettings = getClusterSettings(); - TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, clusterSettings)); - TelemetryPlugin telemetryPlugin1 = mock(TelemetryPlugin.class); - TelemetryPlugin telemetryPlugin2 = mock(TelemetryPlugin.class); - TelemetryPlugin telemetryPlugin3 = mock(TelemetryPlugin.class); - TracingTelemetry tracingTelemetry1 = mock(TracingTelemetry.class); - TracingTelemetry tracingTelemetry2 = mock(TracingTelemetry.class); - TracingTelemetry tracingTelemetry3 = mock(TracingTelemetry.class); - when(telemetryPlugin1.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry1; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(telemetryPlugin1.getName()).thenReturn("otel"); - when(telemetryPlugin2.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry2; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(telemetryPlugin2.getName()).thenReturn("foo"); - when(telemetryPlugin3.getTelemetry(telemetrySettings)).thenReturn(Optional.of(new Telemetry() { - @Override - public TracingTelemetry getTracingTelemetry() { - return tracingTelemetry3; - } - - @Override - public MetricsTelemetry getMetricsTelemetry() { - return null; - } - })); - when(telemetryPlugin3.getName()).thenReturn("bar"); try { - List telemetryPlugins = List.of(telemetryPlugin1, telemetryPlugin2, telemetryPlugin3); - TelemetryModule telemetryModule = new TelemetryModule(settings, telemetryPlugins, telemetrySettings); + TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, any()); } catch (Exception e) { - assertTrue(e instanceof IllegalArgumentException); - assertEquals("Cannot register more than one custom telemetry", e.getMessage()); + assertEquals("Cannot register more than one telemetry", e.getMessage()); } } - private Set> getClusterSettings() { - Set> allTracerSettings = new HashSet<>(); - ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); + public void testGetTelemetryWithNoPlugins() { + TelemetryPlugin telemetryPlugin = mock(TelemetryPlugin.class); + when(telemetryPlugin.getName()).thenReturn("otel"); + TelemetryModule telemetryModule = new TelemetryModule(List.of(telemetryPlugin), any()); + + assertFalse(telemetryModule.getTelemetry().isPresent()); - return allTracerSettings; } + } diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java index 1e3ed1adaa0f4..9d56bd6dd62b2 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import static org.mockito.Mockito.mock; @@ -49,7 +50,7 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); Telemetry mockTelemetry = mock(Telemetry.class); when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); - tracerFactory = new TracerFactory(telemetrySettings, mockTelemetry, mock(ThreadPool.class)); + tracerFactory = new TracerFactory(telemetrySettings, Optional.of(mockTelemetry), mock(ThreadPool.class)); Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof DefaultTracer); From 55650278005f530be5234dd0b7e53452316193a7 Mon Sep 17 00:00:00 2001 From: suranjay Date: Sat, 24 Jun 2023 17:35:58 +0530 Subject: [PATCH 28/38] Fix javadocs error Signed-off-by: suranjay --- .../opensearch/telemetry/tracing/SpanReference.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java index a7c32082e54e2..99d1bd3c93c84 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/SpanReference.java @@ -15,14 +15,26 @@ public class SpanReference { private Span span; + /** + * Creates the wrapper with given span + * @param span the span object to wrap + */ public SpanReference(Span span) { this.span = span; } + /** + * Returns the span object + * @return underlying span + */ public Span getSpan() { return span; } + /** + * Updates the underlying span + * @param span underlying span + */ public void setSpan(Span span) { this.span = span; } From c15cc62b1b75f0fd03c20d7444b7a582e3ced9e0 Mon Sep 17 00:00:00 2001 From: suranjay Date: Sat, 24 Jun 2023 18:43:23 +0530 Subject: [PATCH 29/38] Fix javadocs error Signed-off-by: suranjay --- .../telemetry/tracing/OTelResourceProvider.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java index 6f5ced4e9348f..d8fe9741bf87f 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java @@ -32,7 +32,13 @@ * This class encapsulates all OpenTelemetry related resources */ public final class OTelResourceProvider { + private OTelResourceProvider() {} + /** + * Creates OpenTelemetry instance with default configuration + * @param settings cluster settings + * @return OpenTelemetry instance + */ public static OpenTelemetry get(Settings settings) { return get( settings, @@ -42,6 +48,14 @@ public static OpenTelemetry get(Settings settings) { ); } + /** + * Creates OpenTelemetry instance with provided configuration + * @param settings cluster settings + * @param spanExporter span exporter instance + * @param contextPropagators context propagator instance + * @param sampler sampler instance + * @return Opentelemetry instance + */ public static OpenTelemetry get(Settings settings, SpanExporter spanExporter, ContextPropagators contextPropagators, Sampler sampler) { Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenSearch")); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() From 59b54dfd40ac3c8c0157502446e18a6f358e898e Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 26 Jun 2023 21:18:47 +0530 Subject: [PATCH 30/38] Address PR comments Signed-off-by: suranjay --- .../telemetry/tracing/DefaultTracer.java | 2 +- .../telemetry/OTelTelemetryModulePlugin.java | 6 ++--- .../telemetry/tracing/OTelSpan.java | 24 +++++++++---------- ...lTelemetryImpl.java => OTelTelemetry.java} | 4 ++-- ...java => OTelTracingContextPropagator.java} | 8 +++---- ...lemetry.java => OTelTracingTelemetry.java} | 10 ++++---- .../OTelTelemetryModulePluginTests.java | 12 ++++++++-- ...=> OTelTracingContextPropagatorTests.java} | 6 ++--- ...ts.java => OTelTracingTelemetryTests.java} | 16 ++++++++++--- .../opensearch/telemetry/TelemetryModule.java | 7 +----- .../telemetry/tracing/TracerFactory.java | 2 +- 11 files changed, 55 insertions(+), 42 deletions(-) rename plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/{OtelTelemetryImpl.java => OTelTelemetry.java} (86%) rename plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/{OtelTracingContextPropagator.java => OTelTracingContextPropagator.java} (90%) rename plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/{OtelTracingTelemetry.java => OTelTracingTelemetry.java} (85%) rename plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/{OtelTracingContextPropagatorTests.java => OTelTracingContextPropagatorTests.java} (93%) rename plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/{OtelTracingTelemetryTests.java => OTelTracingTelemetryTests.java} (78%) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index e7535761a3c5f..636702e624f01 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -106,7 +106,7 @@ private void setCurrentSpanInContext(Span span) { tracerContextStorage.put(CURRENT_SPAN, span); } - private void addDefaultAttributes(Span span) { + protected void addDefaultAttributes(Span span) { span.addAttribute(THREAD_NAME, Thread.currentThread().getName()); } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java index 098cade87cac5..2655756fd7e86 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java @@ -15,8 +15,8 @@ import org.opensearch.plugins.TelemetryPlugin; import org.opensearch.telemetry.metrics.MetricsTelemetry; import org.opensearch.telemetry.tracing.OTelResourceProvider; -import org.opensearch.telemetry.tracing.OtelTelemetryImpl; -import org.opensearch.telemetry.tracing.OtelTracingTelemetry; +import org.opensearch.telemetry.tracing.OTelTelemetry; +import org.opensearch.telemetry.tracing.OTelTracingTelemetry; import java.util.Arrays; import java.util.List; @@ -85,7 +85,7 @@ public String getName() { } private Telemetry telemetry() { - return new OtelTelemetryImpl(new OtelTracingTelemetry(OTelResourceProvider.get(settings)), new MetricsTelemetry() { + return new OTelTelemetry(new OTelTracingTelemetry(OTelResourceProvider.get(settings)), new MetricsTelemetry() { }); } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index 6760d44c85861..c1095e1aa9350 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -16,55 +16,55 @@ */ class OTelSpan extends AbstractSpan { - private final Span otelSpan; + private final Span oTelSpan; public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan) { super(spanName, parentSpan); - this.otelSpan = span; + this.oTelSpan = span; } @Override public void endSpan() { - otelSpan.end(); + oTelSpan.end(); } @Override public void addAttribute(String key, String value) { - otelSpan.setAttribute(key, value); + oTelSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Long value) { - otelSpan.setAttribute(key, value); + oTelSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Double value) { - otelSpan.setAttribute(key, value); + oTelSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Boolean value) { - otelSpan.setAttribute(key, value); + oTelSpan.setAttribute(key, value); } @Override public void addEvent(String event) { - otelSpan.addEvent(event); + oTelSpan.addEvent(event); } @Override public String getTraceId() { - return otelSpan.getSpanContext().getTraceId(); + return oTelSpan.getSpanContext().getTraceId(); } @Override public String getSpanId() { - return otelSpan.getSpanContext().getSpanId(); + return oTelSpan.getSpanContext().getSpanId(); } - io.opentelemetry.api.trace.Span getOtelSpan() { - return otelSpan; + io.opentelemetry.api.trace.Span getoTelSpan() { + return oTelSpan; } } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTelemetry.java similarity index 86% rename from plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTelemetry.java index 1d2eb4a176ebf..282fabd43346b 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTelemetryImpl.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTelemetry.java @@ -14,7 +14,7 @@ /** * Otel implementation of Telemetry */ -public class OtelTelemetryImpl implements Telemetry { +public class OTelTelemetry implements Telemetry { private final TracingTelemetry tracingTelemetry; private final MetricsTelemetry metricsTelemetry; @@ -24,7 +24,7 @@ public class OtelTelemetryImpl implements Telemetry { * @param tracingTelemetry tracing telemetry * @param metricsTelemetry metrics telemetry */ - public OtelTelemetryImpl(TracingTelemetry tracingTelemetry, MetricsTelemetry metricsTelemetry) { + public OTelTelemetry(TracingTelemetry tracingTelemetry, MetricsTelemetry metricsTelemetry) { this.tracingTelemetry = tracingTelemetry; this.metricsTelemetry = metricsTelemetry; } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java similarity index 90% rename from plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java index 445aac9fd946f..3fa4de2a5d137 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagator.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java @@ -19,15 +19,15 @@ /** * Otel implementation of TracingContextPropagator */ -public class OtelTracingContextPropagator implements TracingContextPropagator { +public class OTelTracingContextPropagator implements TracingContextPropagator { private final OpenTelemetry openTelemetry; /** - * Creates OtelTracingContextPropagator instance + * Creates OTelTracingContextPropagator instance * @param openTelemetry Otel OpenTelemetry instance */ - public OtelTracingContextPropagator(OpenTelemetry openTelemetry) { + public OTelTracingContextPropagator(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; } @@ -48,7 +48,7 @@ public void inject(Span currentSpan, BiConsumer setter) { } private static Context context(OTelSpan oTelSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getOtelSpan().getSpanContext())); + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getoTelSpan().getSpanContext())); } private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java similarity index 85% rename from plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java index aad7773bf456c..39a4cf3bb7545 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OtelTracingTelemetry.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java @@ -19,9 +19,9 @@ /** * OTel based Telemetry provider */ -public class OtelTracingTelemetry implements TracingTelemetry { +public class OTelTracingTelemetry implements TracingTelemetry { - private static final Logger logger = LogManager.getLogger(OtelTracingTelemetry.class); + private static final Logger logger = LogManager.getLogger(OTelTracingTelemetry.class); private final OpenTelemetry openTelemetry; private final io.opentelemetry.api.trace.Tracer otelTracer; @@ -30,7 +30,7 @@ public class OtelTracingTelemetry implements TracingTelemetry { * Creates OTel based Telemetry * @param openTelemetry OpenTelemetry instance */ - public OtelTracingTelemetry(OpenTelemetry openTelemetry) { + public OTelTracingTelemetry(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; this.otelTracer = openTelemetry.getTracer("os-tracer"); @@ -52,7 +52,7 @@ public Span createSpan(String spanName, Span parentSpan) { @Override public TracingContextPropagator getContextPropagator() { - return new OtelTracingContextPropagator(openTelemetry); + return new OTelTracingContextPropagator(openTelemetry); } private Span createOtelSpan(String spanName, Span parentSpan) { @@ -63,6 +63,6 @@ private Span createOtelSpan(String spanName, Span parentSpan) { io.opentelemetry.api.trace.Span otelSpan(String spanName, Span parentOTelSpan) { return parentOTelSpan == null || !(parentOTelSpan instanceof OTelSpan) ? otelTracer.spanBuilder(spanName).startSpan() - : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getOtelSpan())).startSpan(); + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getoTelSpan())).startSpan(); } } diff --git a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java index 8391933fa5d87..31e17b9ee0229 100644 --- a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java @@ -12,16 +12,20 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; -import org.opensearch.telemetry.tracing.OtelTracingTelemetry; +import org.opensearch.telemetry.tracing.OTelTracingTelemetry; import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.OpenSearchTestCase; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Optional; import static org.opensearch.telemetry.OTelTelemetryModulePlugin.OTEL_TRACER_NAME; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_DELAY_SETTING; +import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; public class OTelTelemetryModulePluginTests extends OpenSearchTestCase { @@ -34,7 +38,11 @@ public void testGetTelemetry() { assertEquals(OTEL_TRACER_NAME, oTelTracerModulePlugin.getName()); TracingTelemetry tracingTelemetry = tracer.get().getTracingTelemetry(); - assertTrue(tracingTelemetry instanceof OtelTracingTelemetry); + assertTrue(tracingTelemetry instanceof OTelTracingTelemetry); + assertEquals( + Arrays.asList(TRACER_EXPORTER_BATCH_SIZE_SETTING, TRACER_EXPORTER_DELAY_SETTING, TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING), + oTelTracerModulePlugin.getSettings() + ); tracingTelemetry.close(); } diff --git a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagatorTests.java similarity index 93% rename from plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagatorTests.java index dc8c66553a7d8..1f76b0b9def18 100644 --- a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingContextPropagatorTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagatorTests.java @@ -23,7 +23,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class OtelTracingContextPropagatorTests extends OpenSearchTestCase { +public class OTelTracingContextPropagatorTests extends OpenSearchTestCase { private static final String TRACE_ID = "4aa59968f31dcbff7807741afa9d7d62"; private static final String SPAN_ID = "bea205cd25756b5e"; @@ -35,7 +35,7 @@ public void testAddTracerContextToHeader() { Map requestHeaders = new HashMap<>(); OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); - TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); + TracingContextPropagator tracingContextPropagator = new OTelTracingContextPropagator(mockOpenTelemetry); tracingContextPropagator.inject(span, (key, value) -> requestHeaders.put(key, value)); assertEquals("00-" + TRACE_ID + "-" + SPAN_ID + "-00", requestHeaders.get("traceparent")); @@ -46,7 +46,7 @@ public void testExtractTracerContextFromHeader() { requestHeaders.put("traceparent", "00-" + TRACE_ID + "-" + SPAN_ID + "-00"); OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); when(mockOpenTelemetry.getPropagators()).thenReturn(ContextPropagators.create(W3CTraceContextPropagator.getInstance())); - TracingContextPropagator tracingContextPropagator = new OtelTracingContextPropagator(mockOpenTelemetry); + TracingContextPropagator tracingContextPropagator = new OTelTracingContextPropagator(mockOpenTelemetry); org.opensearch.telemetry.tracing.Span span = tracingContextPropagator.extract(requestHeaders); assertEquals(TRACE_ID, span.getTraceId()); assertEquals(SPAN_ID, span.getSpanId()); diff --git a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingTelemetryTests.java similarity index 78% rename from plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingTelemetryTests.java index 3cd7af2881a47..7dec7824b9790 100644 --- a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OtelTracingTelemetryTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/tracing/OTelTracingTelemetryTests.java @@ -19,7 +19,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class OtelTracingTelemetryTests extends OpenSearchTestCase { +public class OTelTracingTelemetryTests extends OpenSearchTestCase { public void testCreateSpanWithoutParent() { OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); @@ -29,7 +29,7 @@ public void testCreateSpanWithoutParent() { when(mockTracer.spanBuilder("span_name")).thenReturn(mockSpanBuilder); when(mockSpanBuilder.startSpan()).thenReturn(mock(io.opentelemetry.api.trace.Span.class)); - TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); + TracingTelemetry tracingTelemetry = new OTelTracingTelemetry(mockOpenTelemetry); Span span = tracingTelemetry.createSpan("span_name", null); verify(mockSpanBuilder, never()).setParent(any()); @@ -47,7 +47,7 @@ public void testCreateSpanWithParent() { Span parentSpan = new OTelSpan("parent_span", mock(io.opentelemetry.api.trace.Span.class), null); - TracingTelemetry tracingTelemetry = new OtelTracingTelemetry(mockOpenTelemetry); + TracingTelemetry tracingTelemetry = new OTelTracingTelemetry(mockOpenTelemetry); Span span = tracingTelemetry.createSpan("span_name", parentSpan); verify(mockSpanBuilder).setParent(any()); @@ -55,4 +55,14 @@ public void testCreateSpanWithParent() { assertEquals("parent_span", span.getParentSpan().getSpanName()); } + public void testGetContextPropagator() { + OpenTelemetry mockOpenTelemetry = mock(OpenTelemetry.class); + Tracer mockTracer = mock(Tracer.class); + when(mockOpenTelemetry.getTracer("os-tracer")).thenReturn(mockTracer); + + TracingTelemetry tracingTelemetry = new OTelTracingTelemetry(mockOpenTelemetry); + + assertTrue(tracingTelemetry.getContextPropagator() instanceof OTelTracingContextPropagator); + } + } diff --git a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java index 9224a180ab894..604c111b0720c 100644 --- a/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java +++ b/server/src/main/java/org/opensearch/telemetry/TelemetryModule.java @@ -33,12 +33,7 @@ public TelemetryModule(List telemetryPlugins, TelemetrySettings } public Optional getTelemetry() { - // if only default(Otel) telemetry is registered, return it - if (telemetry != null) { - return Optional.of(telemetry); - } else { - return Optional.empty(); - } + return Optional.ofNullable(telemetry); } private void registerTelemetry(Telemetry factory) { diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java index 69a2d051ee3a3..c2d09ae287beb 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java @@ -79,7 +79,7 @@ private Tracer getOrCreateDefaultTracerInstance() { if (defaultTracer == null) { logger.info("Creating default tracer..."); TracingTelemetry tracingTelemetry = telemetry.get().getTracingTelemetry(); - TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( + TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( threadPool.getThreadContext(), tracingTelemetry ); From 41574017cb59fcee2d12c6da7203790ef08fcab9 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 26 Jun 2023 21:31:41 +0530 Subject: [PATCH 31/38] Fix javadocs error Signed-off-by: suranjay --- .../java/org/opensearch/telemetry/tracing/DefaultTracer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index 636702e624f01..7adad6d1d5866 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -106,6 +106,10 @@ private void setCurrentSpanInContext(Span span) { tracerContextStorage.put(CURRENT_SPAN, span); } + /** + * Adds default attributes in the span + * @param span the current active span + */ protected void addDefaultAttributes(Span span) { span.addAttribute(THREAD_NAME, Thread.currentThread().getName()); } From 01acc4afbd71f3ff85213e98901c1476c7798607 Mon Sep 17 00:00:00 2001 From: suranjay Date: Mon, 26 Jun 2023 22:45:59 +0530 Subject: [PATCH 32/38] Add unit tests coverage Signed-off-by: suranjay --- .../telemetry/tracing/noop/NoopSpan.java | 56 ------------------- .../telemetry/tracing/TracerFactoryTests.java | 1 + 2 files changed, 1 insertion(+), 56 deletions(-) delete mode 100644 libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java deleted file mode 100644 index 07a4f4c7e4aad..0000000000000 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopSpan.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.telemetry.tracing.noop; - -import org.opensearch.telemetry.tracing.Span; -import org.opensearch.telemetry.tracing.AbstractSpan; - -/** - * No-op implementation of Span - */ -public class NoopSpan extends AbstractSpan { - - /** - * Creates a no-op span - * @param spanName span's name - * @param parentSpan span's parent span - */ - public NoopSpan(String spanName, Span parentSpan) { - super(spanName, parentSpan); - } - - @Override - public void endSpan() {} - - @Override - public void addAttribute(String key, String value) {} - - @Override - public void addAttribute(String key, Long value) {} - - @Override - public void addAttribute(String key, Double value) {} - - @Override - public void addAttribute(String key, Boolean value) {} - - @Override - public void addEvent(String event) {} - - @Override - public String getTraceId() { - return null; - } - - @Override - public String getSpanId() { - return null; - } - -} diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java index 9d56bd6dd62b2..cf292c2de6b64 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java @@ -43,6 +43,7 @@ public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof NoopTracer); + assertTrue(tracer.startSpan("foo") == Scope.NO_OP); } public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { From b1d87afd363c2777dcbb8cfe49f1cd45523a8893 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Mon, 26 Jun 2023 14:10:14 -0400 Subject: [PATCH 33/38] Introduce ThreadContextStatePropagator to propagate request and transient headers within ThreadContext Signed-off-by: Andriy Redko --- .../telemetry/tracing/DefaultTracer.java | 10 +- .../tracing/TracerContextStorage.java | 5 + .../telemetry/tracing/DefaultTracerTests.java | 11 +-- .../common/util/concurrent/ThreadContext.java | 96 ++++++++++++------- .../ThreadContextStatePropagator.java | 31 ++++++ .../main/java/org/opensearch/node/Node.java | 2 +- .../TaskThreadContextStatePropagator.java | 38 ++++++++ ...hreadContextBasedTracerContextStorage.java | 39 +++++++- .../telemetry/tracing/TracerFactory.java | 16 +--- .../telemetry/tracing/TracerFactoryTests.java | 6 +- 10 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 server/src/main/java/org/opensearch/common/util/concurrent/ThreadContextStatePropagator.java create mode 100644 server/src/main/java/org/opensearch/tasks/TaskThreadContextStatePropagator.java diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index 7adad6d1d5866..0b5bc34bbbd66 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -19,12 +19,6 @@ * */ public class DefaultTracer implements Tracer { - - /** - * Key for storing current span - */ - public static final String CURRENT_SPAN = "current_span"; - static final String THREAD_NAME = "th_name"; private final TracingTelemetry tracingTelemetry; @@ -95,7 +89,7 @@ public void close() throws IOException { // Visible for testing Span getCurrentSpan() { - return tracerContextStorage.get(CURRENT_SPAN); + return tracerContextStorage.get(TracerContextStorage.CURRENT_SPAN); } private Span createSpan(String spanName, Span parentSpan) { @@ -103,7 +97,7 @@ private Span createSpan(String spanName, Span parentSpan) { } private void setCurrentSpanInContext(Span span) { - tracerContextStorage.put(CURRENT_SPAN, span); + tracerContextStorage.put(TracerContextStorage.CURRENT_SPAN, span); } /** diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java index a31f1fa541075..eb93006835332 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/TracerContextStorage.java @@ -14,6 +14,11 @@ * @param value type */ public interface TracerContextStorage { + /** + * Key for storing current span + */ + String CURRENT_SPAN = "current_span"; + /** * Fetches value corresponding to key * @param key of the tracing context diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index ce563c6ceacb4..f2203ec20d116 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -16,7 +16,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; -import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; public class DefaultTracerTests extends OpenSearchTestCase { @@ -47,19 +46,19 @@ public void testCreateSpan() { public void testEndSpan() { DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); defaultTracer.startSpan("span_name"); - verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); + verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockSpan); defaultTracer.endSpan(); verify(mockSpan).endSpan(); - verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); + verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockParentSpan); } public void testEndSpanByClosingScope() { DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); try (Scope scope = defaultTracer.startSpan("span_name")) { - verify(mockTracerContextStorage).put(CURRENT_SPAN, mockSpan); + verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockSpan); } - verify(mockTracerContextStorage).put(CURRENT_SPAN, mockParentSpan); + verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockParentSpan); } public void testAddSpanAttributeString() { @@ -127,7 +126,7 @@ private void setupMocks() { when(mockSpan.getParentSpan()).thenReturn(mockParentSpan); when(mockParentSpan.getSpanId()).thenReturn("parent_span_id"); when(mockParentSpan.getTraceId()).thenReturn("trace_id"); - when(mockTracerContextStorage.get(CURRENT_SPAN)).thenReturn(mockParentSpan, mockSpan); + when(mockTracerContextStorage.get(TracerContextStorage.CURRENT_SPAN)).thenReturn(mockParentSpan, mockSpan); when(mockTracingTelemetry.createSpan("span_name", mockParentSpan)).thenReturn(mockSpan); } } diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java index 40c28d9463c92..025fb7a36b684 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java @@ -44,9 +44,8 @@ import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; import org.opensearch.http.HttpTransportSettings; -import org.opensearch.telemetry.tracing.SpanReference; import org.opensearch.tasks.Task; -import org.opensearch.telemetry.tracing.TracerFactory; +import org.opensearch.tasks.TaskThreadContextStatePropagator; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -58,7 +57,9 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; import java.util.function.Function; @@ -68,8 +69,6 @@ import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_COUNT; import static org.opensearch.http.HttpTransportSettings.SETTING_HTTP_MAX_WARNING_HEADER_SIZE; -import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; -import static org.opensearch.telemetry.tracing.DefaultTracer.CURRENT_SPAN; /** * A ThreadContext is a map of string headers and a transient map of keyed objects that are associated with @@ -116,6 +115,7 @@ public final class ThreadContext implements Writeable { private final ThreadLocal threadLocal; private final int maxWarningHeaderCount; private final long maxWarningHeaderSize; + private final List propagators; /** * Creates a new ThreadContext instance @@ -126,6 +126,15 @@ public ThreadContext(Settings settings) { this.threadLocal = ThreadLocal.withInitial(() -> DEFAULT_CONTEXT); this.maxWarningHeaderCount = SETTING_HTTP_MAX_WARNING_HEADER_COUNT.get(settings); this.maxWarningHeaderSize = SETTING_HTTP_MAX_WARNING_HEADER_SIZE.get(settings).getBytes(); + this.propagators = new CopyOnWriteArrayList<>(List.of(new TaskThreadContextStatePropagator())); + } + + public void registerThreadContextStatePropagator(final ThreadContextStatePropagator propagator) { + propagators.add(Objects.requireNonNull(propagator)); + } + + public void unregisterThreadContextStatePropagator(final ThreadContextStatePropagator propagator) { + propagators.remove(Objects.requireNonNull(propagator)); } /** @@ -150,15 +159,9 @@ public StoredContext stashContext() { ); } - if (context.transientHeaders.containsKey(TASK_ID)) { - threadContextStruct = threadContextStruct.putTransient(TASK_ID, context.transientHeaders.get(TASK_ID)); - } - - if (context.transientHeaders.containsKey(CURRENT_SPAN)) { - threadContextStruct = threadContextStruct.putTransient( - CURRENT_SPAN, - new SpanReference(((SpanReference) context.transientHeaders.get(CURRENT_SPAN)).getSpan()) - ); + final Map transientHeaders = propagateTransients(context.transientHeaders); + if (!transientHeaders.isEmpty()) { + threadContextStruct = threadContextStruct.putTransient(transientHeaders); } threadLocal.set(threadContextStruct); @@ -176,7 +179,10 @@ public StoredContext stashContext() { */ public Writeable captureAsWriteable() { final ThreadContextStruct context = threadLocal.get(); - return out -> context.writeTo(out, defaultHeader); + return out -> { + final Map propagatedHeaders = propagateHeaders(context.transientHeaders); + context.writeTo(out, defaultHeader, propagatedHeaders); + }; } /** @@ -234,17 +240,24 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders) { */ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collection transientHeadersToClear) { final ThreadContextStruct originalContext = threadLocal.get(); + final Map newTransientHeaders = new HashMap<>(originalContext.transientHeaders); + + boolean transientHeadersModified = false; + final Map transientHeaders = propagateTransients(originalContext.transientHeaders); + if (!transientHeaders.isEmpty()) { + newTransientHeaders.putAll(transientHeaders); + transientHeadersModified = true; + } + // clear specific transient headers from the current context - Map newTransientHeaders = null; for (String transientHeaderToClear : transientHeadersToClear) { - if (originalContext.transientHeaders.containsKey(transientHeaderToClear)) { - if (newTransientHeaders == null) { - newTransientHeaders = new HashMap<>(originalContext.transientHeaders); - } + if (newTransientHeaders.containsKey(transientHeaderToClear)) { newTransientHeaders.remove(transientHeaderToClear); + transientHeadersModified = true; } } - if (newTransientHeaders != null) { + + if (transientHeadersModified == true) { ThreadContextStruct threadContextStruct = new ThreadContextStruct( originalContext.requestHeaders, originalContext.responseHeaders, @@ -257,13 +270,6 @@ public StoredContext newStoredContext(boolean preserveResponseHeaders, Collectio // this is the context when this method returns final ThreadContextStruct newContext = threadLocal.get(); - if (newContext.transientHeaders.containsKey(CURRENT_SPAN)) { - newContext.transientHeaders.put( - CURRENT_SPAN, - new SpanReference(((SpanReference) newContext.transientHeaders.get(CURRENT_SPAN)).getSpan()) - ); - } - return () -> { if (preserveResponseHeaders && threadLocal.get() != newContext) { threadLocal.set(originalContext.putResponseHeaders(threadLocal.get().responseHeaders)); @@ -312,7 +318,9 @@ public Supplier wrapRestorable(StoredContext storedContext) { @Override public void writeTo(StreamOutput out) throws IOException { - threadLocal.get().writeTo(out, defaultHeader); + final ThreadContextStruct context = threadLocal.get(); + final Map propagatedHeaders = propagateHeaders(context.transientHeaders); + context.writeTo(out, defaultHeader, propagatedHeaders); } /** @@ -540,6 +548,18 @@ public static Map buildDefaultHeaders(Settings settings) { } } + private Map propagateTransients(Map source) { + final Map transients = new HashMap<>(); + propagators.forEach(p -> transients.putAll(p.transients(source))); + return transients; + } + + private Map propagateHeaders(Map source) { + final Map headers = new HashMap<>(); + propagators.forEach(p -> headers.putAll(p.headers(source))); + return headers; + } + private static final class ThreadContextStruct { private static final ThreadContextStruct EMPTY = new ThreadContextStruct( @@ -713,6 +733,14 @@ private ThreadContextStruct putResponse( return new ThreadContextStruct(requestHeaders, newResponseHeaders, transientHeaders, isSystemContext, newWarningHeaderSize); } + private ThreadContextStruct putTransient(Map values) { + Map newTransient = new HashMap<>(this.transientHeaders); + for (Map.Entry entry : values.entrySet()) { + putSingleHeader(entry.getKey(), entry.getValue(), newTransient); + } + return new ThreadContextStruct(requestHeaders, responseHeaders, newTransient, isSystemContext); + } + private ThreadContextStruct putTransient(String key, Object value) { Map newTransient = new HashMap<>(this.transientHeaders); putSingleHeader(key, value, newTransient); @@ -727,19 +755,15 @@ private ThreadContextStruct copyHeaders(Iterable> head return putHeaders(newHeaders); } - private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { - if (transientHeaders.containsKey(CURRENT_SPAN)) { - TracerFactory.propagator.inject( - ((SpanReference) transientHeaders.get(CURRENT_SPAN)).getSpan(), - (key, value) -> requestHeaders.put(key, value) - ); - } + private void writeTo(StreamOutput out, Map defaultHeaders, Map propagatedHeaders) + throws IOException { final Map requestHeaders; - if (defaultHeaders.isEmpty()) { + if (defaultHeaders.isEmpty() && propagatedHeaders.isEmpty()) { requestHeaders = this.requestHeaders; } else { requestHeaders = new HashMap<>(defaultHeaders); requestHeaders.putAll(this.requestHeaders); + requestHeaders.putAll(propagatedHeaders); } out.writeVInt(requestHeaders.size()); diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContextStatePropagator.java b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContextStatePropagator.java new file mode 100644 index 0000000000000..b3fc79c5446db --- /dev/null +++ b/server/src/main/java/org/opensearch/common/util/concurrent/ThreadContextStatePropagator.java @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.common.util.concurrent; + +import java.util.Map; + +/** + * The propagator for {@link ThreadContext} that helps to carry-over the state from one + * thread to another (tasks, tracing context, etc). + */ +public interface ThreadContextStatePropagator { + /** + * Returns the list of transient headers that needs to be propagated from current context to new thread context. + * @param source current context transient headers + * @return the list of transient headers that needs to be propagated from current context to new thread context + */ + Map transients(Map source); + + /** + * Returns the list of request headers that needs to be propagated from current context to request. + * @param source current context headers + * @return the list of request headers that needs to be propagated from current context to request + */ + Map headers(Map source); +} diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index 6ab6e78a49238..3742c817118da 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -1032,7 +1032,7 @@ protected Node( final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings()); List telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class); TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, telemetrySettings); - tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool); + tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool.getThreadContext()); } else { tracerFactory = new NoopTracerFactory(); } diff --git a/server/src/main/java/org/opensearch/tasks/TaskThreadContextStatePropagator.java b/server/src/main/java/org/opensearch/tasks/TaskThreadContextStatePropagator.java new file mode 100644 index 0000000000000..ed111b34f048f --- /dev/null +++ b/server/src/main/java/org/opensearch/tasks/TaskThreadContextStatePropagator.java @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.tasks; + +import org.opensearch.common.util.concurrent.ThreadContextStatePropagator; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.opensearch.tasks.TaskResourceTrackingService.TASK_ID; + +/** + * Propagates TASK_ID across thread contexts + */ +public class TaskThreadContextStatePropagator implements ThreadContextStatePropagator { + @Override + public Map transients(Map source) { + final Map transients = new HashMap<>(); + + if (source.containsKey(TASK_ID)) { + transients.put(TASK_ID, source.get(TASK_ID)); + } + + return transients; + } + + @Override + public Map headers(Map source) { + return Collections.emptyMap(); + } +} diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java index 87307085236dd..0d0b795fdc715 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/ThreadContextBasedTracerContextStorage.java @@ -9,21 +9,26 @@ package org.opensearch.telemetry.tracing; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.common.util.concurrent.ThreadContextStatePropagator; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; import java.util.Optional; /** * Core's ThreadContext based TracerContextStorage implementation */ -public class ThreadContextBasedTracerContextStorage implements TracerContextStorage { +public class ThreadContextBasedTracerContextStorage implements TracerContextStorage, ThreadContextStatePropagator { private final ThreadContext threadContext; private final TracingTelemetry tracingTelemetry; public ThreadContextBasedTracerContextStorage(ThreadContext threadContext, TracingTelemetry tracingTelemetry) { - this.threadContext = threadContext; - this.tracingTelemetry = tracingTelemetry; + this.threadContext = Objects.requireNonNull(threadContext); + this.tracingTelemetry = Objects.requireNonNull(tracingTelemetry); + this.threadContext.registerThreadContextStatePropagator(this); } @Override @@ -44,6 +49,34 @@ public void put(String key, Span span) { } } + @Override + public Map transients(Map source) { + final Map transients = new HashMap<>(); + + if (source.containsKey(CURRENT_SPAN)) { + final SpanReference current = (SpanReference) source.get(CURRENT_SPAN); + if (current != null) { + transients.put(CURRENT_SPAN, new SpanReference(current.getSpan())); + } + } + + return transients; + } + + @Override + public Map headers(Map source) { + final Map headers = new HashMap<>(); + + if (source.containsKey(CURRENT_SPAN)) { + final SpanReference current = (SpanReference) source.get(CURRENT_SPAN); + if (current != null) { + tracingTelemetry.getContextPropagator().inject(current.getSpan(), (key, value) -> headers.put(key, value)); + } + } + + return headers; + } + Span getCurrentSpan(String key) { Optional optionalSpanFromContext = spanFromThreadContext(key); return optionalSpanFromContext.orElse(spanFromHeader()); diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java index c2d09ae287beb..306e246471e3b 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java @@ -10,10 +10,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.telemetry.Telemetry; import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.telemetry.tracing.noop.NoopTracer; -import org.opensearch.threadpool.ThreadPool; import java.io.Closeable; import java.io.IOException; @@ -33,18 +33,12 @@ public class TracerFactory implements Closeable { private final Object mutex = new Object(); private final TelemetrySettings telemetrySettings; private final Optional telemetry; - private final ThreadPool threadPool; + private final ThreadContext threadContext; - // TODO Hack, fix me - public static TracingContextPropagator propagator; - - public TracerFactory(TelemetrySettings telemetrySettings, Optional telemetry, ThreadPool threadPool) { + public TracerFactory(TelemetrySettings telemetrySettings, Optional telemetry, ThreadContext threadContext) { this.telemetrySettings = telemetrySettings; this.telemetry = telemetry; - this.threadPool = threadPool; - if (telemetry != null && telemetry.isPresent()) { - propagator = telemetry.get().getTracingTelemetry().getContextPropagator(); - } + this.threadContext = threadContext; } /** @@ -80,7 +74,7 @@ private Tracer getOrCreateDefaultTracerInstance() { logger.info("Creating default tracer..."); TracingTelemetry tracingTelemetry = telemetry.get().getTracingTelemetry(); TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( - threadPool.getThreadContext(), + threadContext, tracingTelemetry ); defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage); diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java index cf292c2de6b64..47fb1a139e0a1 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java @@ -13,10 +13,10 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.telemetry.Telemetry; import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.ThreadPool; import org.opensearch.telemetry.tracing.noop.NoopTracer; import java.util.HashSet; @@ -39,7 +39,7 @@ public void close() { public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Settings settings = Settings.builder().put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), false).build(); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); - tracerFactory = new TracerFactory(telemetrySettings, null, mock(ThreadPool.class)); + tracerFactory = new TracerFactory(telemetrySettings, null, new ThreadContext(Settings.EMPTY)); Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof NoopTracer); @@ -51,7 +51,7 @@ public void testGetTracerWithTracingEnabledReturnsDefaultTracer() { TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); Telemetry mockTelemetry = mock(Telemetry.class); when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); - tracerFactory = new TracerFactory(telemetrySettings, Optional.of(mockTelemetry), mock(ThreadPool.class)); + tracerFactory = new TracerFactory(telemetrySettings, Optional.of(mockTelemetry), new ThreadContext(Settings.EMPTY)); Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof DefaultTracer); From 830af09a5a5bcc99085bc5e108e7353c61f80901 Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 27 Jun 2023 00:55:11 +0530 Subject: [PATCH 34/38] Remove optional telemetry Signed-off-by: suranjay --- .../telemetry/tracing/TracerFactory.java | 47 ++++++------------- .../telemetry/tracing/TracerFactoryTests.java | 4 +- 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java index 306e246471e3b..8228cded4c822 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/TracerFactory.java @@ -29,16 +29,14 @@ public class TracerFactory implements Closeable { private static final Logger logger = LogManager.getLogger(TracerFactory.class); - private volatile Tracer defaultTracer; - private final Object mutex = new Object(); private final TelemetrySettings telemetrySettings; - private final Optional telemetry; - private final ThreadContext threadContext; + private final Tracer defaultTracer; public TracerFactory(TelemetrySettings telemetrySettings, Optional telemetry, ThreadContext threadContext) { this.telemetrySettings = telemetrySettings; - this.telemetry = telemetry; - this.threadContext = threadContext; + this.defaultTracer = telemetry.map(Telemetry::getTracingTelemetry) + .map(tracingTelemetry -> createDefaultTracer(tracingTelemetry, threadContext)) + .orElse(NoopTracer.INSTANCE); } /** @@ -46,7 +44,7 @@ public TracerFactory(TelemetrySettings telemetrySettings, Optional te * @return tracer instance */ public Tracer getTracer() { - return isTracingDisabled() || !telemetry.isPresent() ? NoopTracer.INSTANCE : getOrCreateDefaultTracerInstance(); + return telemetrySettings.isTracingEnabled() ? defaultTracer : NoopTracer.INSTANCE; } /** @@ -54,34 +52,19 @@ public Tracer getTracer() { */ @Override public void close() { - if (defaultTracer != null) { - try { - defaultTracer.close(); - } catch (IOException e) { - logger.warn("Error closing tracer", e); - } + try { + defaultTracer.close(); + } catch (IOException e) { + logger.warn("Error closing tracer", e); } } - private boolean isTracingDisabled() { - return !telemetrySettings.isTracingEnabled(); - } - - private Tracer getOrCreateDefaultTracerInstance() { - if (defaultTracer == null) { - synchronized (mutex) { - if (defaultTracer == null) { - logger.info("Creating default tracer..."); - TracingTelemetry tracingTelemetry = telemetry.get().getTracingTelemetry(); - TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( - threadContext, - tracingTelemetry - ); - defaultTracer = new DefaultTracer(tracingTelemetry, tracerContextStorage); - } - } - } - return defaultTracer; + private Tracer createDefaultTracer(TracingTelemetry tracingTelemetry, ThreadContext threadContext) { + TracerContextStorage tracerContextStorage = new ThreadContextBasedTracerContextStorage( + threadContext, + tracingTelemetry + ); + return new DefaultTracer(tracingTelemetry, tracerContextStorage); } } diff --git a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java index 47fb1a139e0a1..7968c6c43afb4 100644 --- a/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java +++ b/server/src/test/java/org/opensearch/telemetry/tracing/TracerFactoryTests.java @@ -39,7 +39,9 @@ public void close() { public void testGetTracerWithTracingDisabledReturnsNoopTracer() { Settings settings = Settings.builder().put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), false).build(); TelemetrySettings telemetrySettings = new TelemetrySettings(settings, new ClusterSettings(settings, getClusterSettings())); - tracerFactory = new TracerFactory(telemetrySettings, null, new ThreadContext(Settings.EMPTY)); + Telemetry mockTelemetry = mock(Telemetry.class); + when(mockTelemetry.getTracingTelemetry()).thenReturn(mock(TracingTelemetry.class)); + tracerFactory = new TracerFactory(telemetrySettings, Optional.of(mockTelemetry), new ThreadContext(Settings.EMPTY)); Tracer tracer = tracerFactory.getTracer(); assertTrue(tracer instanceof NoopTracer); From 5d28259641b1e0a29a792e64663dd1141510f39c Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 27 Jun 2023 01:37:11 +0530 Subject: [PATCH 35/38] Fix NPE Signed-off-by: suranjay --- .../org/opensearch/telemetry/tracing/NoopTracerFactory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java b/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java index 9b158307c2371..3d7f8133788ce 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/NoopTracerFactory.java @@ -10,12 +10,14 @@ import org.opensearch.telemetry.tracing.noop.NoopTracer; +import java.util.Optional; + /** * No-op implementation of TracerFactory */ public class NoopTracerFactory extends TracerFactory { public NoopTracerFactory() { - super(null, null, null); + super(null, Optional.empty(), null); } @Override From 7a8f1c7959c7ac98c4ab30c965ae883332a76eb6 Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 27 Jun 2023 11:27:10 +0530 Subject: [PATCH 36/38] Use created span Signed-off-by: suranjay --- .../telemetry/tracing/DefaultTracer.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index 0b5bc34bbbd66..b9f6fcec33603 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -40,16 +40,13 @@ public Scope startSpan(String spanName) { Span span = createSpan(spanName, getCurrentSpan()); setCurrentSpanInContext(span); addDefaultAttributes(span); - return new ScopeImpl(() -> endSpan()); + return new ScopeImpl(() -> endSpan(span)); } @Override public void endSpan() { Span currentSpan = getCurrentSpan(); - if (currentSpan != null) { - currentSpan.endSpan(); - setCurrentSpanInContext(currentSpan.getParentSpan()); - } + endSpan(currentSpan); } @Override @@ -92,6 +89,13 @@ Span getCurrentSpan() { return tracerContextStorage.get(TracerContextStorage.CURRENT_SPAN); } + private void endSpan(Span span) { + if (span != null) { + span.endSpan(); + setCurrentSpanInContext(span.getParentSpan()); + } + } + private Span createSpan(String spanName, Span parentSpan) { return tracingTelemetry.createSpan(spanName, parentSpan); } From f2b14175e3fae94f041cfc27949fe104ce22f87e Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 27 Jun 2023 18:12:33 +0530 Subject: [PATCH 37/38] Rename plugin class Signed-off-by: suranjay --- plugins/telemetry-otel/build.gradle | 2 +- ...tryModulePlugin.java => OTelTelemetryPlugin.java} | 4 ++-- .../telemetry/tracing/OTelResourceProvider.java | 6 +++--- ...luginTests.java => OTelTelemetryPluginTests.java} | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) rename plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/{OTelTelemetryModulePlugin.java => OTelTelemetryPlugin.java} (94%) rename plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/{OTelTelemetryModulePluginTests.java => OTelTelemetryPluginTests.java} (74%) diff --git a/plugins/telemetry-otel/build.gradle b/plugins/telemetry-otel/build.gradle index d4cf654f41b2a..7a56621be5f1e 100644 --- a/plugins/telemetry-otel/build.gradle +++ b/plugins/telemetry-otel/build.gradle @@ -13,7 +13,7 @@ import org.opensearch.gradle.info.BuildParams opensearchplugin { description 'Opentelemetry based telemetry implementation.' - classname 'org.opensearch.telemetry.OTelTelemetryModulePlugin' + classname 'org.opensearch.telemetry.OTelTelemetryPlugin' hasClientJar = true } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryPlugin.java similarity index 94% rename from plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java rename to plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryPlugin.java index 2655756fd7e86..1c38c9dc8d6be 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryModulePlugin.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/OTelTelemetryPlugin.java @@ -25,7 +25,7 @@ /** * Telemetry plugin based on Otel */ -public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin { +public class OTelTelemetryPlugin extends Plugin implements TelemetryPlugin { static final String OTEL_TRACER_NAME = "otel"; @@ -65,7 +65,7 @@ public class OTelTelemetryModulePlugin extends Plugin implements TelemetryPlugin * Creates Otel plugin * @param settings cluster settings */ - public OTelTelemetryModulePlugin(Settings settings) { + public OTelTelemetryPlugin(Settings settings) { this.settings = settings; } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java index d8fe9741bf87f..04bade9ec942a 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelResourceProvider.java @@ -24,9 +24,9 @@ import java.util.concurrent.TimeUnit; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_DELAY_SETTING; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_DELAY_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; /** * This class encapsulates all OpenTelemetry related resources diff --git a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryPluginTests.java similarity index 74% rename from plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java rename to plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryPluginTests.java index 31e17b9ee0229..c6ffba04ac285 100644 --- a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryModulePluginTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/OTelTelemetryPluginTests.java @@ -22,18 +22,18 @@ import java.util.Set; import java.util.Optional; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.OTEL_TRACER_NAME; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_DELAY_SETTING; -import static org.opensearch.telemetry.OTelTelemetryModulePlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.OTEL_TRACER_NAME; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_BATCH_SIZE_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_DELAY_SETTING; +import static org.opensearch.telemetry.OTelTelemetryPlugin.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING; -public class OTelTelemetryModulePluginTests extends OpenSearchTestCase { +public class OTelTelemetryPluginTests extends OpenSearchTestCase { public void testGetTelemetry() { Set> allTracerSettings = new HashSet<>(); ClusterSettings.FEATURE_FLAGGED_CLUSTER_SETTINGS.get(List.of(FeatureFlags.TELEMETRY)).stream().forEach((allTracerSettings::add)); Settings settings = Settings.builder().build(); - OTelTelemetryModulePlugin oTelTracerModulePlugin = new OTelTelemetryModulePlugin(settings); + OTelTelemetryPlugin oTelTracerModulePlugin = new OTelTelemetryPlugin(settings); Optional tracer = oTelTracerModulePlugin.getTelemetry(null); assertEquals(OTEL_TRACER_NAME, oTelTracerModulePlugin.getName()); From 7637b3713b56d8cd4a658feb6c608ae30150f82f Mon Sep 17 00:00:00 2001 From: suranjay Date: Tue, 27 Jun 2023 21:17:12 +0530 Subject: [PATCH 38/38] Remove endSpan method Signed-off-by: suranjay --- .../telemetry/tracing/DefaultTracer.java | 6 ----- .../opensearch/telemetry/tracing/Tracer.java | 8 +------ .../telemetry/tracing/noop/NoopTracer.java | 3 --- .../telemetry/tracing/DefaultTracerTests.java | 10 -------- .../telemetry/tracing/OTelSpan.java | 24 +++++++++---------- .../tracing/OTelTracingContextPropagator.java | 2 +- .../tracing/OTelTracingTelemetry.java | 2 +- 7 files changed, 15 insertions(+), 40 deletions(-) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java index b9f6fcec33603..ab9110af7c3ab 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java @@ -43,12 +43,6 @@ public Scope startSpan(String spanName) { return new ScopeImpl(() -> endSpan(span)); } - @Override - public void endSpan() { - Span currentSpan = getCurrentSpan(); - endSpan(currentSpan); - } - @Override public void addSpanAttribute(String key, String value) { Span currentSpan = getCurrentSpan(); diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java index 1a27770eb9758..fcc091eb39c48 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java @@ -22,16 +22,10 @@ public interface Tracer extends Closeable { * Starts the {@link Span} with given name * * @param spanName span name - * @return scope of the span, can be used with try-with-resources to close the span + * @return scope of the span, must be closed with explicit close or with try-with-resource */ Scope startSpan(String spanName); - /** - * Ends the current active {@link Span} - * - */ - void endSpan(); - /** * Adds string attribute to the current active {@link Span}. * diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java index 9a36c8c665e97..18fc60e41e54d 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java @@ -28,9 +28,6 @@ public Scope startSpan(String spanName) { return Scope.NO_OP; } - @Override - public void endSpan() {} - /** * @param key attribute key * @param value attribute value diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java index f2203ec20d116..f0e8f3c2e2344 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java @@ -43,16 +43,6 @@ public void testCreateSpan() { Assert.assertEquals("span_name", defaultTracer.getCurrentSpan().getSpanName()); } - public void testEndSpan() { - DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); - defaultTracer.startSpan("span_name"); - verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockSpan); - - defaultTracer.endSpan(); - verify(mockSpan).endSpan(); - verify(mockTracerContextStorage).put(TracerContextStorage.CURRENT_SPAN, mockParentSpan); - } - public void testEndSpanByClosingScope() { DefaultTracer defaultTracer = new DefaultTracer(mockTracingTelemetry, mockTracerContextStorage); try (Scope scope = defaultTracer.startSpan("span_name")) { diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index c1095e1aa9350..23a2d9baa3e6e 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -16,55 +16,55 @@ */ class OTelSpan extends AbstractSpan { - private final Span oTelSpan; + private final Span delegateSpan; public OTelSpan(String spanName, Span span, org.opensearch.telemetry.tracing.Span parentSpan) { super(spanName, parentSpan); - this.oTelSpan = span; + this.delegateSpan = span; } @Override public void endSpan() { - oTelSpan.end(); + delegateSpan.end(); } @Override public void addAttribute(String key, String value) { - oTelSpan.setAttribute(key, value); + delegateSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Long value) { - oTelSpan.setAttribute(key, value); + delegateSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Double value) { - oTelSpan.setAttribute(key, value); + delegateSpan.setAttribute(key, value); } @Override public void addAttribute(String key, Boolean value) { - oTelSpan.setAttribute(key, value); + delegateSpan.setAttribute(key, value); } @Override public void addEvent(String event) { - oTelSpan.addEvent(event); + delegateSpan.addEvent(event); } @Override public String getTraceId() { - return oTelSpan.getSpanContext().getTraceId(); + return delegateSpan.getSpanContext().getTraceId(); } @Override public String getSpanId() { - return oTelSpan.getSpanContext().getSpanId(); + return delegateSpan.getSpanContext().getSpanId(); } - io.opentelemetry.api.trace.Span getoTelSpan() { - return oTelSpan; + io.opentelemetry.api.trace.Span getDelegateSpan() { + return delegateSpan; } } diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java index 3fa4de2a5d137..15609b39b6b94 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingContextPropagator.java @@ -48,7 +48,7 @@ public void inject(Span currentSpan, BiConsumer setter) { } private static Context context(OTelSpan oTelSpan) { - return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getoTelSpan().getSpanContext())); + return Context.current().with(io.opentelemetry.api.trace.Span.wrap(oTelSpan.getDelegateSpan().getSpanContext())); } private static final TextMapSetter> TEXT_MAP_SETTER = (carrier, key, value) -> { diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java index 39a4cf3bb7545..8a0034e098461 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelTracingTelemetry.java @@ -63,6 +63,6 @@ private Span createOtelSpan(String spanName, Span parentSpan) { io.opentelemetry.api.trace.Span otelSpan(String spanName, Span parentOTelSpan) { return parentOTelSpan == null || !(parentOTelSpan instanceof OTelSpan) ? otelTracer.spanBuilder(spanName).startSpan() - : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getoTelSpan())).startSpan(); + : otelTracer.spanBuilder(spanName).setParent(Context.current().with(((OTelSpan) parentOTelSpan).getDelegateSpan())).startSpan(); } }