Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion java-backend/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 21 additions & 18 deletions java-backend/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 61 additions & 42 deletions java-backend/MIGRATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,88 @@
# OpenTelemetry to OneAgent SDK Migration Summary
# OneAgent SDK to OpenTelemetry Migration Summary

## Migration Completed ✅

The Java backend application has been successfully migrated from OpenTelemetry to Dynatrace OneAgent SDK for Java.
The Java backend application has been successfully reverted from Dynatrace OneAgent SDK back to OpenTelemetry OTLP exporter using environment variables.

## Changes Made

### 1. Maven Dependencies Updated (`pom.xml`)
- ✅ Removed OpenTelemetry dependencies:
- `io.opentelemetry:opentelemetry-api`
- ✅ Removed OneAgent SDK dependency:
- `com.dynatrace.oneagent.sdk.java:oneagent-sdk:1.9.0`

- ✅ Added OpenTelemetry dependencies:
- `io.opentelemetry:opentelemetry-sdk`
- `io.opentelemetry:opentelemetry-exporter-otlp`
- `io.opentelemetry:opentelemetry-sdk-trace`
- `io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter`
- `io.micrometer:micrometer-tracing-bridge-otel`

- ✅ Added OneAgent SDK dependency:
- `com.dynatrace.oneagent.sdk.java:oneagent-sdk:1.9.0`

### 2. Configuration Classes Replaced

#### Removed:
- ❌ `src/main/java/com/shopper/config/OpenTelemetryConfig.java`
- ❌ `src/main/java/com/shopper/config/DynatraceOtelLogHook.java`
- ❌ `src/main/java/com/shopper/config/OneAgentConfig.java`

#### Added:
- ✅ `src/main/java/com/shopper/config/OneAgentConfig.java`
- OneAgent SDK initialization and status checking
- Logging callback configuration
- Service metadata configuration

- ✅ `src/main/java/com/shopper/config/DynatraceOneAgentLogHook.java`
- Custom service tracing for feature flag evaluation
- Integration with DevCycle hooks
- Request attributes for flag context

### 3. Service Classes Enhanced

#### `UserService.java` - Authentication Tracing
- ✅ Added OneAgent SDK custom service tracing for:
- User registration (`user_registration.register`)
- User authentication (`user_authentication.login`)
- ✅ Custom request attributes:
- `username`, `email`, `assigned_role`, `user_id`, `user_role`
- ✅ Error handling and logging integration

#### `DualDatabaseStrategyImpl.java` - Database Request Tracing
- ✅ Added OneAgent SDK database request tracing
- ✅ Separate tracing for primary (SQLite) and secondary (PostgreSQL) databases
- ✅ Operation type tracking: SELECT, INSERT/UPDATE, SELECT (fallback)
- ✅ Database vendor and connection information
- ✅ `src/main/java/com/shopper/config/OpenTelemetryConfig.java`
- OTLP exporter configuration with environment variables
- Resource attributes and service metadata
- Automatic instrumentation support

#### Retained:
- ✅ `src/main/java/com/shopper/config/DynatraceOneAgentHook.java`
- Uses OpenTelemetry API for feature flag evaluation tracing
- Integration with DevCycle hooks remains unchanged

### 3. Service Classes Reverted

#### `DualDatabaseStrategyImpl.java` - Database Operations Simplified
- ✅ Removed OneAgent SDK database request tracing
- ✅ Simplified to direct operation execution
- ✅ Automatic instrumentation via OpenTelemetry Java Agent will handle tracing

#### `UserService.java` - Authentication Operations
- ✅ Reverted to standard Spring Security operations
- ✅ Automatic instrumentation via OpenTelemetry Java Agent will handle tracing

### 4. Configuration Files Updated

#### `application.yml`
- ✅ Removed OpenTelemetry OTLP configuration
- ✅ Simplified telemetry configuration for OneAgent SDK
- ✅ Updated comments to reflect OneAgent SDK usage
- ✅ Added OpenTelemetry OTLP exporter configuration
- ✅ Configured environment variable support for OTLP endpoint
- ✅ Set up resource attributes and service metadata

## Current Configuration

#### `application.properties`
- ✅ Removed OpenTelemetry endpoint and token configuration
- ✅ Kept essential telemetry project metadata
- ✅ Updated documentation comments
The application now uses:
- **OpenTelemetry Java Agent** for automatic instrumentation
- **OTLP exporter** configured via environment variables
- **run-with-otel.sh** script for easy deployment with proper OTLP configuration
- **Preserved deployment scripts** from previous migrations

## Usage

Run the application with OpenTelemetry instrumentation:

```bash
./run-with-otel.sh
```

Configure telemetry endpoints via environment variables:

```bash
# For local OneAgent OTLP endpoint
export USE_LOCAL_OTLP=true
./run-with-otel.sh

# For direct Dynatrace endpoint
export DYNATRACE_ENV_URL="https://your-env.live.dynatrace.com"
export DYNATRACE_API_TOKEN="your-api-token"
./run-with-otel.sh
```

### 5. OpenFeature Integration Updated
### 5. OpenFeature Integration Updated
- ✅ Removed OneAgent SDK dependency from OpenFeatureConfig
- ✅ Updated hook registration messaging to reflect OpenTelemetry usage

#### `OpenFeatureConfig.java`
- ✅ Replaced OpenTelemetry Tracer dependency with OneAgentSDK
Expand Down
68 changes: 68 additions & 0 deletions java-backend/README_OPENTELEMETRY_REVERSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# OpenTelemetry Reversion Complete ✅

## Summary

The Java backend has been successfully reverted from Dynatrace OneAgent SDK back to OpenTelemetry OTLP exporter using environment variables, while preserving all deployment and build scripts.

## What Was Changed

### 1. Dependencies (pom.xml)
- **Removed:** `com.dynatrace.oneagent.sdk.java:oneagent-sdk:1.9.0`
- **Added:** Full OpenTelemetry SDK dependencies including OTLP exporter

### 2. Configuration Files
- **Removed:** `OneAgentConfig.java`
- **Added:** `OpenTelemetryConfig.java` with OTLP exporter configuration
- **Updated:** `application.yml` with OpenTelemetry configuration
- **Updated:** `OpenFeatureConfig.java` to remove OneAgent dependency

### 3. Service Classes
- **Reverted:** `DualDatabaseStrategyImpl.java` - removed OneAgent SDK database tracing
- **Kept:** `UserService.java` unchanged (no OneAgent integration was present)

### 4. Deployment Scripts (Preserved)
- ✅ `run-with-otel.sh` - Fully functional with environment variable configuration
- ✅ `deploy.sh` - Deployment script preserved
- ✅ `run.sh` - Basic run script preserved
- ✅ `docker-compose.yml` - Docker configuration preserved

## How to Use

### Quick Start
```bash
# Run with default configuration (no telemetry export)
./run-with-otel.sh

# Run with local OneAgent OTLP endpoint
USE_LOCAL_OTLP=true ./run-with-otel.sh

# Run with direct Dynatrace endpoint
DYNATRACE_ENV_URL="https://your-env.live.dynatrace.com" \
DYNATRACE_API_TOKEN="your-api-token" \
./run-with-otel.sh
```

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `USE_LOCAL_OTLP` | Use local OneAgent OTLP endpoint | `false` |
| `DYNATRACE_ENV_URL` | Direct Dynatrace environment URL | - |
| `DYNATRACE_API_TOKEN` | Dynatrace API token for direct access | - |
| `LOCAL_OTLP_PORT` | Local OTLP port | `14499` |

## Benefits of This Configuration

1. **Environment Variable Driven:** Easy configuration without code changes
2. **Flexible Deployment:** Works with local OneAgent or direct Dynatrace
3. **Automatic Instrumentation:** Uses OpenTelemetry Java Agent for comprehensive coverage
4. **Preserved Scripts:** All deployment and build scripts retained
5. **Feature Flag Tracing:** DevCycle hooks continue to work with OpenTelemetry API

## Verification

The application will log telemetry configuration on startup:
```
📊 OpenTelemetry Auto-Instrumentation enabled for service: java-backend v1.0.0 (development)
🔗 OpenTelemetry configured for OTLP endpoint: http://localhost:14499/otlp
```
Loading