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

Observability provider #154

wants to merge 28 commits into from

Conversation

fmeheust
Copy link
Member

This provider is intended to replace the Open Telemetry provider and integrates with both Open Telemetry and Java Flight Recorder.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 25, 2025
@fmeheust fmeheust requested a review from ejannett March 3, 2025 14:44
/**
* Logger
*/
private Logger logger = Logger.getLogger(ObservabilityTraceEventListenerProvider.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

not static ?

protected static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();;


static {
Copy link
Member

Choose a reason for hiding this comment

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

What is the need of this static block ?

try {
objectName = new ObjectName(MBEAN_OBJECT_NAME);
} catch (MalformedObjectNameException e) {
objectName = null;
Copy link
Member

Choose a reason for hiding this comment

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

Our ObjectName name is fixed. This exception case will never happen.
And what will be the later consequences of objectName being null ?


@Override
public TraceEventListener getTraceEventListener(Map<Parameter, CharSequence> map) {
try {
Copy link
Member

Choose a reason for hiding this comment

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

It seems quite costly here, especially as we are registering a singleton. Why not moving this elsewhere ?


private String initAndGetTraceState(Span span) {
final TraceState traceState = span.getSpanContext().getTraceState();
final StringBuilder stringBuilder = new StringBuilder();
Copy link
Member

Choose a reason for hiding this comment

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

Why not

final StringBuilder stringBuilder = new StringBuilder("tracestate: ");
traceState.forEach((k, v) -> stringBuilder.append(k).append("=").append(v));
return stringBuilder.append("\r\n").toString();

Are we not missing a comma or something else between key/values ?

final String parentId = spanContext.getSpanId();
final String traceFlags = spanContext.getTraceFlags().toString();

return String.format("traceparent: %s-%s-%s-%s\r\n",
Copy link
Member

Choose a reason for hiding this comment

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

What is the "contract" regarding the format return ?
It looks like kind of toString() but this is used in the API which usually imply stronger specification.
(same apply to return of initAndGetTraceState())

/**
* Logger
*/
private Logger logger = Logger.getLogger(OpenTelemetryTraceEventListenerProvider.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

Should be static.

General note about loggers : unless there is a justification to have a specific logger for a class, We usually see loggers being instantiated in a higher level context
i.e logger = Logger.getLogger(OpenTelemetryTraceEventListenerProvider.class..getPackage().getName());

*/
private Logger logger = Logger.getLogger(OpenTelemetryTraceEventListenerProvider.class.getName());

private static ObjectName objectName;
Copy link
Member

Choose a reason for hiding this comment

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

same remark as for the use of ObjectName above

assertEquals("OK", resultSet.getString(1));
}
}
recording.stop();
Copy link
Member

Choose a reason for hiding this comment

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

General remark about test classes: please few comments about what they do when appropriate

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 sucess
Copy link
Member

Choose a reason for hiding this comment

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

Typo: 'sucess' should be corrected to 'success'.

* AC begin and sucess
* VIP down event

The following attributes are added the the traces for each event:
Copy link
Member

Choose a reason for hiding this comment

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

Typo: 'the the' should be corrected to 'to the'.

@@ -0,0 +1,90 @@
package oracle.jdbc.provider.observability;
Copy link
Member

Choose a reason for hiding this comment

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

missing copyright

*/
private static final String SENSITIVE_DATA_ENABLED = "oracle.jdbc.provider.observability.sensitiveDataEnabled";

private static final ReentrantLock observabilityConfiguraitonLock = new ReentrantLock();
Copy link
Member

Choose a reason for hiding this comment

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

Typo in variable name: 'observabilityConfiguraitonLock' should be 'observabilityConfigurationLock'.

String enabledTracers = System.getProperty(ENABLED_TRACERS, "OTEL,JFR");
String sensitiveDataEnabled = System.getProperty(SENSITIVE_DATA_ENABLED, "false");
setEnabledTracers(enabledTracers);
setSensitiveDataEnabled(Boolean.valueOf(sensitiveDataEnabled));
Copy link
Member

Choose a reason for hiding this comment

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

Consider using Boolean.parseBoolean() instead of Boolean.valueOf() as it directly returns a primitive boolean rather than creating a Boolean object that needs to be unboxed.

*/
JFR(new JFRTracer());

private ObservabilityTracer tracer;
Copy link
Member

Choose a reason for hiding this comment

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

we can mark tracer as final

* @return a user context object that is passed to the next call on this
* Connection. May be null.
*/
Object traceRoundtrip(Sequence sequence, TraceContext traceContext, Object userContext);
Copy link
Member

Choose a reason for hiding this comment

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

maybe we need to rename this method to traceRoundTrip for consistency

/**
* Name of the property used to enable or disable this listener.
*/
public static final String OPEN_TELEMENTRY_TRACE_EVENT_LISTENER_ENABLED = "oracle.jdbc.provider.opentelemetry.enabled";
Copy link
Member

Choose a reason for hiding this comment

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

There's a typo in the constant name OPEN_TELEMENTRY. It should be OPEN_TELEMETRY

* Name of the property used to enable or disable sensitive data for this
* listener.
*/
public static final String OPEN_TELEMENTRY_TRACE_EVENT_LISTENER_SENSITIVE_ENABLED = "oracle.jdbc.provider.opentelemetry.sensitive-enabled";
Copy link
Member

Choose a reason for hiding this comment

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

same here

public TraceEventListener getTraceEventListener(Map<Parameter, CharSequence> map) {
try {
if (!server.isRegistered(objectName)) {
boolean enabled = Boolean.valueOf(System.getProperty(OPEN_TELEMENTRY_TRACE_EVENT_LISTENER_ENABLED, "true"));
Copy link
Member

Choose a reason for hiding this comment

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

same here Boolean.parseBoolean() instead of Boolean.valueOf()

Copy link
Member

@ejannett ejannett left a comment

Choose a reason for hiding this comment

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

looks good.

@@ -0,0 +1,86 @@
################################################################################
# Copyright (c) 2024 Oracle and/or its affiliates.
Copy link
Member

Choose a reason for hiding this comment

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

we should update the copyright to 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants