Skip to content

Commit 226094f

Browse files
committed
Simplify OpenTelemetry span context API and improve miri test mocks
- Simplify SpanFromContext function signature from (uint64, bool) to uint64 - Remove redundant 'found' boolean return value - Functions now return 0 to indicate no parent span available - Update DefaultSpanFromContext and all related implementations - Improve error handling and panic recovery logic - Add mock-logger-core package for miri tests - Create no-op implementations of log functions (error, warn, debug, info) - Add proper Cargo.toml configuration and dependency integration - Ensure miri tests can run without complex logging infrastructure - Enhance mock-telemetry for better miri test coverage - Implement Display trait for TraceError - Add concrete implementations for GlideOpenTelemetry methods - Replace todo!() placeholders with working mock implementations - Add span_from_pointer method for completeness - Update Go client span extraction logic - Simplify parent span detection from context - Remove unnecessary tuple unpacking in executeCommandWithRoute and executeBatch - Maintain backward compatibility while improving code clarity - Add comprehensive OpenTelemetry examples and documentation - Create opentelemetry_examples_test.go with runnable examples - Update examples.md to reference new OpenTelemetry examples - Move extensive documentation from inline comments to dedicated examples - Provide clear usage patterns for span context management This change improves the developer experience by simplifying the OpenTelemetry integration API while maintaining full functionality and backward compatibility. The miri test improvements ensure better test coverage in memory-safe environments. Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
1 parent 5d7c7bc commit 226094f

File tree

9 files changed

+187
-312
lines changed

9 files changed

+187
-312
lines changed

ffi/miri-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ protobuf = { version = "3", features = [] }
99
redis = { path = "./mock-redis", package = "mock-redis" }
1010
glide-core = { path = "./mock-glide-core", package = "mock-glide-core" }
1111
tokio = { path = "./mock-tokio", package = "mock-tokio" }
12+
logger_core = { path = "./mock-logger-core", package = "mock-logger-core" }
1213

1314
[lib]
1415
path = "../src/lib.rs"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "mock-logger-core"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2+
3+
// Mock logger_core implementation for miri tests
4+
// These functions are no-ops to avoid any complex logging infrastructure
5+
6+
pub fn log_error(_module: &str, _message: impl std::fmt::Display) {
7+
// No-op for miri tests
8+
}
9+
10+
pub fn log_warn(_module: &str, _message: impl std::fmt::Display) {
11+
// No-op for miri tests
12+
}
13+
14+
pub fn log_debug(_module: &str, _message: impl std::fmt::Display) {
15+
// No-op for miri tests
16+
}
17+
18+
pub fn log_info(_module: &str, _message: impl std::fmt::Display) {
19+
// No-op for miri tests
20+
}

ffi/miri-tests/mock-telemetry/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ pub struct GlideSpan;
1717
#[derive(Debug)]
1818
pub struct TraceError;
1919

20+
impl fmt::Display for TraceError {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
write!(f, "trace error")
23+
}
24+
}
25+
2026
impl GlideSpan {
2127
pub fn add_span(&self, _name: &str) -> Result<GlideSpan, TraceError> {
2228
Ok(GlideSpan)
@@ -76,11 +82,15 @@ pub struct GlideOpenTelemetry;
7682

7783
impl GlideOpenTelemetry {
7884
pub fn initialise(_config: GlideOpenTelemetryConfig) -> Result<(), GlideOTELError> {
79-
todo!()
85+
Ok(())
8086
}
8187

8288
pub fn new_span(_name: &str) -> GlideSpan {
83-
todo!()
89+
GlideSpan
90+
}
91+
92+
pub unsafe fn span_from_pointer(_ptr: u64) -> Result<GlideSpan, TraceError> {
93+
Ok(GlideSpan)
8494
}
8595
}
8696

@@ -91,5 +101,3 @@ impl fmt::Display for GlideOTELError {
91101
write!(f, "error")
92102
}
93103
}
94-
95-

go/base_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (client *baseClient) executeCommandWithRoute(
293293
otelInstance := GetOtelInstance()
294294
if otelInstance != nil && otelInstance.shouldSample() {
295295
// Check if there's a parent span in the context
296-
if parentSpanPtr, found := otelInstance.extractSpanPointer(ctx); found {
296+
if parentSpanPtr := otelInstance.extractSpanPointer(ctx); parentSpanPtr != 0 {
297297
// Create child span with parent
298298
spanPtr = otelInstance.createSpanWithParent(requestType, parentSpanPtr)
299299
} else {
@@ -423,7 +423,7 @@ func (client *baseClient) executeBatch(
423423
otelInstance := GetOtelInstance()
424424
if otelInstance != nil && otelInstance.shouldSample() {
425425
// Check if there's a parent span in the context
426-
if parentSpanPtr, found := otelInstance.extractSpanPointer(ctx); found {
426+
if parentSpanPtr := otelInstance.extractSpanPointer(ctx); parentSpanPtr != 0 {
427427
// Create child batch span with parent
428428
// Since we don't have create_batch_otel_span_with_parent, we create a named child span
429429
// using the parent span pointer to establish the parent-child relationship

go/examples/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Go provides native support for Examples which are a great way to document how to
99
- [hash_commands_test.go](../hash_commands_test.go)
1010
- [hyperloglog_commands_test.go](../hyperloglog_commands_test.go)
1111
- [list_commands_test.go](../list_commands_test.go)
12+
- [opentelemetry_examples_test.go](../opentelemetry_examples_test.go)
1213
- [server_management_commands_test.go](../server_management_commands_test.go)
1314
- [set_commands_test.go](../set_commands_test.go)
1415
- [sorted_set_commands_test.go](../sorted_set_commands_test.go)

0 commit comments

Comments
 (0)