From d2372c0475176c2cb96ca78bd854f1b48ecaa859 Mon Sep 17 00:00:00 2001 From: jonny rhea Date: Tue, 6 Jan 2026 17:28:39 -0600 Subject: [PATCH] add additional comments and license header --- internal/telemetry/telemetry.go | 21 ++++++++++++++++++++- rpc/tracing_test.go | 13 ++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index 4652c15543..2a6bd45907 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -1,3 +1,19 @@ +// Copyright 2026 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + package telemetry import ( @@ -9,12 +25,15 @@ import ( "go.opentelemetry.io/otel/trace" ) +// Attribute is an alias for attribute.KeyValue. type Attribute = attribute.KeyValue +// StringAttribute creates an attribute with a string value. func StringAttribute(key, val string) Attribute { return attribute.String(key, val) } +// Int64Attribute creates an attribute with an int64 value. func Int64Attribute(key string, val int64) Attribute { return attribute.Int64(key, val) } @@ -45,7 +64,7 @@ func StartSpanWithTracer(ctx context.Context, tracer trace.Tracer, spanName stri // Define the function to end the span and handle error recording spanEnd := func(err *error) { if *err != nil { - // Error occurred, record it and set status on span and parent + // Error occurred, record it and set status on span span.RecordError(*err) span.SetStatus(codes.Error, (*err).Error()) } diff --git a/rpc/tracing_test.go b/rpc/tracing_test.go index 1772d2ef08..62b3999949 100644 --- a/rpc/tracing_test.go +++ b/rpc/tracing_test.go @@ -68,13 +68,18 @@ func TestTracingHTTP(t *testing.T) { } t.Cleanup(client.Close) + // Make a successful RPC call. var result echoResult if err := client.Call(&result, "test_echo", "hello", 42, &echoArgs{S: "world"}); err != nil { t.Fatalf("RPC call failed: %v", err) } + + // Flush spans. if err := tracer.ForceFlush(context.Background()); err != nil { t.Fatalf("failed to flush: %v", err) } + + // Check spans. spans := exporter.GetSpans() if len(spans) == 0 { t.Fatal("no spans were emitted") @@ -98,7 +103,8 @@ func TestTracingHTTP(t *testing.T) { } } -func TestTracingHTTPShouldFail(t *testing.T) { +// TestTracingHTTPMethodNotFound verifies that a span is emitted when rpc method does not exist. +func TestTracingHTTPMethodNotFound(t *testing.T) { t.Parallel() server, tracer, exporter := newTracingServer(t) httpsrv := httptest.NewServer(server) @@ -109,13 +115,18 @@ func TestTracingHTTPShouldFail(t *testing.T) { } t.Cleanup(client.Close) + // Make a RPC call that should fail. var result echoResult if err := client.Call(&result, "testnonexistent", "hello", 42, &echoArgs{S: "world"}); err == nil { t.Fatalf("RPC call should have failed") } + + // Flush spans. if err := tracer.ForceFlush(context.Background()); err != nil { t.Fatalf("failed to flush: %v", err) } + + // Check spans. spans := exporter.GetSpans() if len(spans) == 0 { t.Fatal("no spans were emitted")