Skip to content

Observability provider #154

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6db2af2
First commit
fmeheust Jan 23, 2025
cf6b82a
Added static Events and tests
fmeheust Feb 3, 2025
5f5fdb8
Replaced set by list
fmeheust Feb 3, 2025
2546b01
Changes to tests
fmeheust Feb 3, 2025
50211a2
Added test name
fmeheust Feb 3, 2025
535737c
Check connectionID
fmeheust Feb 3, 2025
65753e8
Static JFR events
fmeheust Feb 10, 2025
fe09409
Merge remote-tracking branch 'origin/main' into observability-provider
fmeheust Feb 10, 2025
ce3601d
Merged from main
fmeheust Feb 10, 2025
bc11b39
Documentation and tests
fmeheust Feb 14, 2025
b469a80
Added execution events to JFR
fmeheust Feb 14, 2025
a6cd874
Documentation changes
fmeheust Feb 21, 2025
8142aa0
Fixed tests
fmeheust Feb 24, 2025
01cfd12
Observability configuration test
fmeheust Feb 24, 2025
ad7df96
Added debug info
fmeheust Feb 24, 2025
ac08356
Run tests one by one
fmeheust Feb 24, 2025
8478b83
Test Order
fmeheust Feb 24, 2025
6b03e6f
Added comment for test run configuration.
fmeheust Feb 24, 2025
c8a8cdf
Backward compatibility
fmeheust Feb 24, 2025
dee07b4
Locks and event labels
fmeheust Feb 25, 2025
c649e57
Refactoring and added possibility to have different configuration and…
fmeheust Mar 7, 2025
65c7765
Changed action version for deprecated action
fmeheust Mar 7, 2025
f6e972f
Set version in pom files correctly
fmeheust Mar 7, 2025
8f7b15d
Fixed tests when running in the same JVM
fmeheust Mar 7, 2025
1157aa3
Unique identifier and refactoring.
fmeheust Mar 7, 2025
ed0c89e
Merge branch 'main' into observability-provider
fmeheust Mar 10, 2025
dd9de05
Corrected copyright
fmeheust Mar 10, 2025
59f3262
Merge branch 'observability-provider' of https://github.com/oracle/oj…
fmeheust Mar 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ jobs:
JACKSON_OSON_USERNAME=${{ secrets.TEST_JACKSON_OSON_USERNAME }}\n
JACKSON_OSON_PASSWORD=${{ secrets.TEST_JACKSON_OSON_PASSWORD }}\n
" >> ojdbc-provider-jackson-oson/test.properties


# Generate ojdbc-provider-observability/test.properties
echo -e "OBSERVABILITY_URL=${{ secrets.TEST_JACKSON_OSON_URL }}\n
OBSERVABILITY_USERNAME=${{ secrets.TEST_JACKSON_OSON_USERNAME }}\n
OBSERVABILITY_PASSWORD=${{ secrets.TEST_JACKSON_OSON_PASSWORD }}\n
" >> ojdbc-provider-observability/test.properties

# Generate ojdbc-provider-aws/test.properties
echo -e "AWS_S3_URL=${{ secrets.TEST_AWS_S3_URL }}\n
AWS_SECRETS_MANAGER_URL=${{ secrets.TEST_AWS_SECRETS_MANAGER_URL }}\n
Expand All @@ -141,5 +147,7 @@ jobs:
rm ojdbc-provider-azure/test.properties

rm ojdbc-provider-jackson-oson/test.properties

rm ojdbc-provider-observability/test.properties

rm ojdbc-provider-aws/test.properties
1 change: 0 additions & 1 deletion ojdbc-provider-jackson-oson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-common</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
Expand Down
133 changes: 133 additions & 0 deletions ojdbc-provider-observability/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Oracle JDBC Observability Provider

This module contains a provider that adds tracing capabilities to the Oracle
JDBC driver. Two tracers are available:
* OTEL: adds Open Telemetry tracing capabilities.
* JFR: exports events to Java Flight Recorder.

This provider implements the TraceEventListener interface provided by the JDBC
driver which will be notified whenever events are generated in the driver and
will publish these events into Open Telemetry. These events include:
* roundtrips to the database server
* AC begin and success
* VIP down event

The following attributes are added the traces for each event:
* **Roundtrips**
* Connection ID
* Database Operation
* Database User
* Database Tenant
* SQL ID
* Original SQL Text *(only present if sensitive data is enabled)*
* Actual SQL Text *(only present if sensitive data is enabled)*
* **AC begin and success**
* Error Message
* Error code
* SQL state
* Current replay retry count
* **VIP down event**
* Error message
* VIP address
* Protocol *(only present if sensitive data is enabled)*
* Host *(only present if sensitive data is enabled)*
* Port *(only present if sensitive data is enabled)*
* Service name *(only present if sensitive data is enabled)*
* SID *(only present if sensitive data is enabled)*
* Connection data *(only present if sensitive data is enabled)*

## Installation

This provider is distributed as single jar on the Maven Central Repository. The
jar is compiled for JDK 11, and is forward compatible with later JDK versions.
The coordinates for the latest release are:

```xml
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-observability</artifactId>
<version>1.0.3</version>
</dependency>
```

## Usage

To use the Oracle JDBC observability provider just add the artifact to the
application's classpath and set the following connection property:

```java
oracle.jdbc.provider.traceEventListener=observability-trace-event-listener-provider
```

A unique identifier connection property allows to identify the trace event
listener. Connections setting the same unique identifier use the same trace
event listener and share the same configuration.

```java
oracle.jdbc.provider.traceEventListener.unique_identifier=<unique identifier>
```

If no unique identifier is provided, the unique idetifier "default" is used.

## Configuration

The provider can be configured by:
* using system properties,
```java
System.setProperty("oracle.jdbc.provider.observability.enabledTracers", "OTEL,JFR");
System.setProperty("oracle.jdbc.provider.observability.sensitiveDataEnabled", "true");
```
* or using the MBean.
```java
ObservabilityTraceEventListener listener = ObservabilityTraceEventListener.getTraceEventListener("<unique identifier>");
ObjectName objectName = new ObjectName(listener.getMBeanObjectName());
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
server.setAttribute(objectName, new Attribute("EnabledTracers", "OTEL,JFR"));
server.setAttribute(objectName, new Attribute("SensitiveDataEnabled", "true"));
```
* it is also possible to use the ObservabilityConfiguration object directly by
calling the
```java
ObservabilityConfiguration configuration = ObservabilityTraceEventListener.getObservabilityConfiguration("<name>");
configuration.setEnabledTracers("OTEL,JFR");
configuration.setSensitiveDataEnabled(true);
```

## Backward compatibility

### Usage

The provider can also be used by setting the following connection property:

```java
oracle.jdbc.provider.traceEventListener=open-telemetry-trace-event-listener-provider
```

When this property is used only the OTEL tracer can be used.

### Configuration

To ensure backward compatibility Oracle JDBC provider for Open Telemetry configuration
properties and MBean have been kept. When these properties and MBean are used only
the Open Telemetry tracer will be enabled.

The Oracle JDBC provider for Open Telemetry can be configured using system properties
or a MBean. Two parameters can be configured:
* **Enabled**: when enabled (*true*) traces will be exported to Open
Telemetry. This property is **enabled by default**.
* **Sensitive data enabled**: when enabled (*true*) attributes containing
sensitive information like SQL statements and connection URL will be included
in the traces. This property is **disabled by default**.

The system properties are "oracle.jdbc.provider.opentelemetry.enabled" and
"oracle.jdbc.provider.opentelemetry.sensitive-enabled" respectively and the MBean
exposes two attributes "Enabled" and "SensitiveDataEnabled".

The sample code below shows how to retrieve the value of an attribute:
```java
ObservabilityTraceEventListener listener = ObservabilityTraceEventListener.getTraceEventListener("<name>");
ObjectName objectName = new ObjectName(listener.getMBeanObjectName());
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
boolean isEnabled = Boolean.valueOf(server.getAttribute(objectName, "Enabled").toString())
.booleanValue();
```
86 changes: 86 additions & 0 deletions ojdbc-provider-observability/example-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
################################################################################
# Copyright (c) 2025 Oracle and/or its affiliates.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or data
# (collectively the "Software"), free of charge and under any and all copyright
# rights in the Software, and any and all patent rights owned or freely
# licensable by each licensor hereunder covering either (i) the unmodified
# Software as contributed to or provided by such licensor, or (ii) the Larger
# Works (as defined below), to deal in both
#
# (a) the Software, and
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software (each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
# The above copyright notice and either this complete permission notice or at
# a minimum a reference to the UPL must be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################

# This file provides examples of properties that configure tests in this
# module.
#
# QUICK GUIDE TO RUNNING TESTS:
# 1. Create a copy of this file named "test.properties":
# cp example-test.properties test.properties
# 2. In test.properties, replace example values with real values (the file is
# .gitignore'd, so sensitive info won't be checked in to the repo)
# 3. Comment out any lines for which a value can not be provided (tests are
# skipped if no value is configured).
# 4. mvn clean verify
#
# CONFIGURING TEST PROPERTIES
# Test properties are read from a properties file by the TestProperties class.
# The TestProperties class can be found in:
# ojdbc-provider-common/src/testFixtures/java/oracle/jdbc/provider/TestProperties.java
# The default behavior of TestProperties is to read a file named
# "test.properties" in the current directory. A non-default location may be
# specified as a JVM system property:
# mvn clean verify -Doracle.jdbc.provider.TestProperties=/path/to/my-test.properties
#
# MAINTAINING THIS FILE
# Project maintainers should add an example to this file anytime they write a
# test which requires a new property. Not doing so will inflict pain and
# suffering upon our fellow programmers, and will also lead to increased
# maintenance costs.
#
# IGNORING UNCONFIGURED PROPERTIES
# No test should cause a build failure due to an unconfigured property.
# Using JUnit terminology: A test should "abort" rather than "fail" when a
# property is not configured. This means that the test does not pass, but it
# does not cause the build to fail either.
# Methods of the TestProperties class will automatically abort a test if a
# property is not configured. The org.junit.jupiter.api.Assumptions class may
# also be used directly to abort a test.
# There is NO environment in which ALL tests can be run. Some tests may
# require authentication as a managed identity in an Azure VM, while other
# tests require authentication as an instance principal in an OCI compute
# instance; These environments are mutually exclusive. This is one reason why
# tests can not fail the build if a required property is not set.
# A more practical reason is that developers may not need to run all tests if
# their changes are isolated to single module. For instance, a developer
# working on an OCI provider should not need to set up an Azure tenancy to test
# their changes.

OBSERVABILITY_URL=<url>
OBSERVABILITY_USERNAME=<username>
OBSERVABILITY_PASSWORD=<password>
73 changes: 73 additions & 0 deletions ojdbc-provider-observability/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.3</version>
</parent>

<name>Oracle JDBC Observability Provider</name>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-observability</artifactId>

<properties>
<opentelemetry.version>1.44.1</opentelemetry.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${opentelemetry.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>ojdbc-provider-common</artifactId>
<groupId>com.oracle.database.jdbc</groupId>
<classifier>tests</classifier>
<type>test-jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--
ObservabilityConfigurationTest must run first and alone since it depends on
ObservabilityConfiguration being started with system properties set on the
test.
Running tests alphabetical and single threaded ensures that.
-->
<parallel>none</parallel>
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading
Loading