Skip to content

Instantly share code, notes, and snippets.

View yurishkuro's full-sized avatar

Yuri Shkuro yurishkuro

View GitHub Profile
@yurishkuro
yurishkuro / graph-15-nodes.json
Created November 21, 2023 15:52
Dependencies 15 nodes
[
{
"parent": "node_0",
"child": "node_7",
"callCount": 4
},
{
"parent": "node_0",
"child": "node_13",
"callCount": 10
@yurishkuro
yurishkuro / tracing.go
Created February 8, 2023 23:10
HotROD external baggage
func (tm *TracedServeMux) AddHandler(pattern string, handler http.Handler) {
middleware := nethttp.Middleware(tm.tracer, handler,
nethttp.MWSpanObserver(func(span opentracing.Span, r *http.Request) {
if !tm.copyBaggage {
return
}
bag := baggage.FromContext(r.Context())
for _, m := range bag.Members() {
span.SetBaggageItem(m.Key(), m.Value())
}
@yurishkuro
yurishkuro / tracing.go
Last active February 8, 2023 23:18
HotROD OTEL propagator
var once sync.Once
// Init initializes OpenTelemetry SDK and uses OTel-OpenTracing Bridge
// to return an OpenTracing-compatible tracer.
func Init(serviceName string, exporterType string, ...) opentracing.Tracer {
once.Do(func() {
propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
))
@yurishkuro
yurishkuro / tracing.go
Created February 6, 2023 08:03
HotROD OTEL exporter
func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
var exporter sdktrace.SpanExporter
var err error
switch exporterType {
case "jaeger":
exporter, err = jaeger.New(
jaeger.WithCollectorEndpoint(),
)
case "otlp":
client := otlptracehttp.NewClient(
@yurishkuro
yurishkuro / tracing.go
Last active February 6, 2023 08:05
HotROD init OpenTelemetry SDK and bridge
// Init initializes OpenTelemetry SDK and uses OTel-OpenTracing Bridge
// to return an OpenTracing-compatible tracer.
func Init(
serviceName string,
exporterType string,
metricsFactory metrics.Factory,
logger log.Factory
) opentracing.Tracer {
exp, err := createOtelExporter(exporterType)
if err != nil {
@yurishkuro
yurishkuro / basic_trace.py
Last active October 4, 2023 00:47
OpenTelemetry Python Example
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(OTLPSpanExporter())
)
tracer = trace.get_tracer(__name__)
@yurishkuro
yurishkuro / lazy_session.go
Created March 10, 2020 16:22
lazy session for Cassandra in Jaeger
package cassandra
import (
"errors"
"sync"
"sync/atomic"
"github.com/jaegertracing/jaeger/pkg/cassandra"
"go.uber.org/zap"
)
@yurishkuro
yurishkuro / contextualLogger.go
Created May 30, 2018 14:49
Contextual logger
type traceLogger {
span opentracing.Span
zl *zap.Logger
l *Logger
}
func (l *Logger) Trace(ctx context.Context) (*zap.Logger, context.Context) {
span := opentracing.SpanFromContext(ctx)
if span == nil {
return l.NoTrace(), ctx
@yurishkuro
yurishkuro / jaeger.proto
Created April 15, 2018 16:26
Experimental protobuf model for Jaeger using gogoprotobuf extensions
/* Jaeger test
Cf. https://github.com/gogo/protobuf/blob/master/extensions.md
Based on https://github.com/gogo/grpc-example
The JSON is generated with the help of "github.com/cockroachdb/cockroach/pkg/util/protoutil"
with `EmitDefaults: false` setting
jsonpb := &protoutil.JSONPb{
EmitDefaults: false,
Indent: " ",
@yurishkuro
yurishkuro / gist:b135e6750df0f95aa86c35a77cc736d4
Created August 5, 2017 00:08
by-value vs. by-pointer benchmark
package jaeger
// go test -bench=.
// BenchmarkByValue-8 2000000000 0.56 ns/op
// BenchmarkByPointer-8 2000000000 0.28 ns/op
import "testing"
func BenchmarkByValue(b *testing.B) {
b1 := b1{}