-
Notifications
You must be signed in to change notification settings - Fork 5
PHP: Add OTEL support #72
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
prateek-kumar-improving
wants to merge
31
commits into
main
Choose a base branch
from
php/add-otel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+698
−13
Open
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
ff90f49
PHP: Add OTEL support
prateek-kumar-improving 807b7da
PHP: Update OTEL tests
prateek-kumar-improving 0f76aa7
PHP: Update type errors
prateek-kumar-improving 0a105f6
PHP: Update OTEL tests
prateek-kumar-improving 290db09
PHP: Update OTEL tests
prateek-kumar-improving f854b3e
PHP: Update OTEL tests
prateek-kumar-improving dc74a75
PHP: Add OTEL APIs
prateek-kumar-improving 0b5628e
PHP: Update OTEL tests
prateek-kumar-improving a42f56c
PHP: Remove OTEL stubs
prateek-kumar-improving 4115930
PHP: Add shouldSample API
prateek-kumar-improving f3fe8ad
PHP: Update formatting in valkey_glide_otel.c
prateek-kumar-improving 27cb998
PHP: Update formatting in valkey_glide_cluster.c
prateek-kumar-improving a7b757b
PHP: Fix tests/ValkeyGlideFeaturesTest.php
prateek-kumar-improving 94e597e
PHP: Fix tests/ValkeyGlideFeaturesTest.php
prateek-kumar-improving 441398d
PHP: Fix tests/ValkeyGlideClusterFeaturesTest.php
prateek-kumar-improving 4f16dfa
PHP: Fix tests/ValkeyGlideClusterFeaturesTest.php
prateek-kumar-improving cab3d84
PHP: Update package.xml
prateek-kumar-improving e7b9418
PHP: Update package.xml
prateek-kumar-improving e8baa8a
PHP: Update formatting in valkey_glide_otel.c
prateek-kumar-improving 6a3abc8
PHP: Update memory issues
prateek-kumar-improving b6d87b2
PHP: Update memory issues
prateek-kumar-improving 4848433
PHP: Update valgrind.supp
prateek-kumar-improving e518a6c
PHP: Update examples
prateek-kumar-improving 1d1593e
PHP: Update examples
prateek-kumar-improving b7c13b8
PHP: Update examples and stubs
prateek-kumar-improving 716f3b0
PHP: Update examples and remove public APIs from stubs
prateek-kumar-improving 3e30be6
PHP: Update valkey_glide_otel_should_sample
prateek-kumar-improving c589fac
PHP: Update valkey_glide_otel.c
prateek-kumar-improving 3ef7fd5
PHP: Update tests
prateek-kumar-improving ac30fa4
PHP: Update tests and add exceptions
prateek-kumar-improving 60fbbc6
PHP: Add memory free in valkey_glide_otel.c
prateek-kumar-improving File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
| /** | ||
| * Example demonstrating OpenTelemetry integration with Valkey GLIDE PHP | ||
| * Following Java/Go patterns with proper defaults | ||
| */ | ||
|
|
||
| require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| try { | ||
| // OTEL configuration for traces and metrics | ||
| // Following Java/Go defaults: sample_percentage=1%, flush_interval_ms=5000 | ||
| $otelConfig = [ | ||
| 'traces' => [ | ||
| 'endpoint' => 'grpc://localhost:4317', // OTEL collector endpoint | ||
| 'sample_percentage' => 10 // Sample 10% of requests (default is 1%) | ||
prateek-kumar-improving marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], | ||
| 'metrics' => [ | ||
| 'endpoint' => 'grpc://localhost:4317' // OTEL collector endpoint | ||
| ], | ||
| 'flush_interval_ms' => 5000 // Flush every 5 seconds (default) | ||
| ]; | ||
|
|
||
| // Create ValkeyGlide client with OTEL configuration | ||
| $client = new ValkeyGlide( | ||
| addresses: [ | ||
| ['host' => 'localhost', 'port' => 6379] | ||
| ], | ||
| use_tls: false, | ||
| credentials: null, | ||
| read_from: ValkeyGlide::READ_FROM_PRIMARY, | ||
| request_timeout: null, | ||
| reconnect_strategy: null, | ||
| database_id: 0, | ||
| client_name: 'otel-example-client', | ||
| client_az: null, | ||
| advanced_config: [ | ||
| 'connection_timeout' => 5000, | ||
| 'otel' => $otelConfig // Add OTEL configuration | ||
| ] | ||
| ); | ||
|
|
||
| echo "ValkeyGlide client created with OpenTelemetry support\n"; | ||
| echo "- Sample percentage: 10% (higher than default 1% for demo)\n"; | ||
| echo "- Flush interval: 5000ms (default)\n"; | ||
| echo "- Traces endpoint: grpc://localhost:4317\n"; | ||
| echo "- Metrics endpoint: grpc://localhost:4317\n\n"; | ||
|
|
||
| // Perform some operations that will be traced | ||
| $client->set('otel:test:key1', 'value1'); | ||
| echo "SET operation completed\n"; | ||
|
|
||
| $value = $client->get('otel:test:key1'); | ||
| echo "GET operation completed: $value\n"; | ||
|
|
||
| $client->set('otel:test:key2', 'value2'); | ||
| $client->set('otel:test:key3', 'value3'); | ||
|
|
||
| // Batch operations will also be traced | ||
| $results = $client->mget(['otel:test:key1', 'otel:test:key2', 'otel:test:key3']); | ||
| echo "MGET operation completed: " . json_encode($results) . "\n"; | ||
|
|
||
| // Cleanup | ||
| $client->del(['otel:test:key1', 'otel:test:key2', 'otel:test:key3']); | ||
| echo "Cleanup completed\n"; | ||
|
|
||
| $client->close(); | ||
| echo "Client closed\n"; | ||
|
|
||
| } catch (Exception $e) { | ||
| echo "Error: " . $e->getMessage() . "\n"; | ||
| exit(1); | ||
| } | ||
|
|
||
| echo "\nOpenTelemetry example completed successfully!\n"; | ||
| echo "Check your OTEL collector for traces and metrics.\n"; | ||
| echo "\nNote: OTEL can only be initialized once per process (like Java/Go).\n"; | ||
prateek-kumar-improving marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "If you need to change configuration, restart the process.\n"; | ||
| ?> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Comprehensive OpenTelemetry Public API Example for Valkey GLIDE PHP | ||
| * | ||
| * This example demonstrates the Java-inspired public OTEL APIs: | ||
prateek-kumar-improving marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * - Static initialization and configuration | ||
| * - Runtime sample percentage control | ||
| * - Manual span creation and management | ||
| * - Integration with automatic command tracing | ||
| */ | ||
|
|
||
| require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| echo "=== Valkey GLIDE PHP OpenTelemetry Public API Example ===\n\n"; | ||
|
|
||
| try { | ||
| // 1. Check initial state | ||
| echo "1. Initial OpenTelemetry state:\n"; | ||
| echo " Initialized: " . (ValkeyGlide::isOpenTelemetryInitialized() ? "Yes" : "No") . "\n"; | ||
| echo " Sample percentage: " . (ValkeyGlide::getOpenTelemetrySamplePercentage() ?? "N/A") . "%\n\n"; | ||
|
|
||
| // 2. Initialize OpenTelemetry with comprehensive configuration | ||
| echo "2. Initializing OpenTelemetry...\n"; | ||
| $config = [ | ||
| 'traces' => [ | ||
| 'endpoint' => 'file:///tmp/valkey_glide_traces.json', | ||
| 'sample_percentage' => 100 // Sample all requests for demo | ||
| ], | ||
| 'metrics' => [ | ||
| 'endpoint' => 'file:///tmp/valkey_glide_metrics.json' | ||
| ], | ||
| 'flush_interval_ms' => 3000 // Flush every 3 seconds | ||
| ]; | ||
|
|
||
| $initialized = ValkeyGlide::initOpenTelemetry($config); | ||
| echo " Result: " . ($initialized ? "Success" : "Already initialized") . "\n"; | ||
|
|
||
| // 3. Verify initialization | ||
| echo " Post-init state:\n"; | ||
| echo " Initialized: " . (ValkeyGlide::isOpenTelemetryInitialized() ? "Yes" : "No") . "\n"; | ||
| echo " Sample percentage: " . ValkeyGlide::getOpenTelemetrySamplePercentage() . "%\n\n"; | ||
|
|
||
| // 4. Test runtime sample percentage control | ||
| echo "3. Testing runtime sample percentage control:\n"; | ||
| echo " Setting sample percentage to 50%...\n"; | ||
| ValkeyGlide::setOpenTelemetrySamplePercentage(50); | ||
| echo " New sample percentage: " . ValkeyGlide::getOpenTelemetrySamplePercentage() . "%\n\n"; | ||
|
|
||
| // 5. Create manual spans for custom tracing | ||
| echo "4. Creating manual spans for custom operations:\n"; | ||
|
|
||
| // Create a parent span for the entire user operation | ||
| $userOperationSpan = ValkeyGlide::createOpenTelemetrySpan("user-checkout-process"); | ||
| echo " Created parent span: " . ($userOperationSpan ? "ID $userOperationSpan" : "Failed") . "\n"; | ||
|
|
||
| // Create child spans for sub-operations | ||
| $validationSpan = ValkeyGlide::createOpenTelemetrySpan("validate-user-data"); | ||
| echo " Created validation span: " . ($validationSpan ? "ID $validationSpan" : "Failed") . "\n"; | ||
prateek-kumar-improving marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Simulate some work | ||
| usleep(100000); // 100ms | ||
|
|
||
| // End validation span | ||
| ValkeyGlide::endOpenTelemetrySpan($validationSpan); | ||
| echo " Ended validation span\n"; | ||
|
|
||
| // 6. Create Valkey client and perform operations (automatic tracing) | ||
| echo "\n5. Creating Valkey client and performing operations:\n"; | ||
|
|
||
| $addresses = [ | ||
| ['host' => 'localhost', 'port' => 6379] | ||
| ]; | ||
|
|
||
| try { | ||
| $client = new ValkeyGlide( | ||
| $addresses, | ||
| false, // use_tls | ||
| null, // credentials | ||
| null, // read_from | ||
| null, // request_timeout | ||
| null, // reconnect_strategy | ||
| null, // client_name | ||
| null, // periodic_checks | ||
| null, // advanced_config | ||
| null, // lazy_connect | ||
| 0 // database_id | ||
| ); | ||
|
|
||
| echo " Client created successfully\n"; | ||
|
|
||
| // These operations will be automatically traced | ||
| $client->set('otel:demo:key1', 'value1'); | ||
| echo " SET operation completed\n"; | ||
|
|
||
| $value = $client->get('otel:demo:key1'); | ||
| echo " GET operation completed, value: $value\n"; | ||
|
|
||
| // Create another manual span for batch operations | ||
| $batchSpan = ValkeyGlide::createOpenTelemetrySpan("batch-operations"); | ||
|
|
||
| // Perform multiple operations | ||
| $client->set('otel:demo:key2', 'value2'); | ||
| $client->set('otel:demo:key3', 'value3'); | ||
| $client->mget(['otel:demo:key1', 'otel:demo:key2', 'otel:demo:key3']); | ||
|
|
||
| ValkeyGlide::endOpenTelemetrySpan($batchSpan); | ||
| echo " Batch operations completed\n"; | ||
|
|
||
| $client->close(); | ||
| echo " Client closed\n"; | ||
|
|
||
| } catch (Exception $e) { | ||
| echo " Client operations failed: " . $e->getMessage() . "\n"; | ||
| echo " (This is expected if Valkey server is not running)\n"; | ||
| } | ||
|
|
||
| // 7. End the parent span | ||
| ValkeyGlide::endOpenTelemetrySpan($userOperationSpan); | ||
| echo " Ended parent span\n\n"; | ||
|
|
||
| // 8. Test error conditions | ||
| echo "6. Testing error conditions:\n"; | ||
prateek-kumar-improving marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| ValkeyGlide::setOpenTelemetrySamplePercentage(150); // Invalid percentage | ||
| } catch (Exception $e) { | ||
| echo " Expected error for invalid percentage: " . $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| try { | ||
| ValkeyGlide::createOpenTelemetrySpan(""); // Empty name | ||
| } catch (Exception $e) { | ||
| echo " Expected error for empty span name: " . $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| try { | ||
| ValkeyGlide::createOpenTelemetrySpan(str_repeat("a", 300)); // Too long name | ||
| } catch (Exception $e) { | ||
| echo " Expected error for long span name: " . $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| // 9. Test duplicate initialization | ||
| echo "\n7. Testing duplicate initialization:\n"; | ||
| $secondInit = ValkeyGlide::initOpenTelemetry($config); | ||
| echo " Second initialization result: " . ($secondInit ? "Success" : "Ignored (expected)") . "\n"; | ||
|
|
||
| // 10. Final state | ||
| echo "\n8. Final OpenTelemetry state:\n"; | ||
| echo " Initialized: " . (ValkeyGlide::isOpenTelemetryInitialized() ? "Yes" : "No") . "\n"; | ||
| echo " Sample percentage: " . ValkeyGlide::getOpenTelemetrySamplePercentage() . "%\n"; | ||
|
|
||
| echo "\n=== Example completed successfully! ===\n"; | ||
prateek-kumar-improving marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Check the following files for telemetry data:\n"; | ||
| echo "- /tmp/valkey_glide_traces.json (traces)\n"; | ||
|
||
| echo "- /tmp/valkey_glide_metrics.json (metrics)\n"; | ||
|
|
||
| } catch (Exception $e) { | ||
| echo "Error: " . $e->getMessage() . "\n"; | ||
| echo "Stack trace:\n" . $e->getTraceAsString() . "\n"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.