mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
add additional comments and license header
This commit is contained in:
parent
60df872d5a
commit
d2372c0475
2 changed files with 32 additions and 2 deletions
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue