用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill tracing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | tracing |
| description | Distributed tracing implementation |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"developer, devops-engineer, sre","category":"devops"} |
Trace
├── Span (Root)
│ ├── Span (Database)
│ │ └── Span (Connection Pool)
│ ├── Span (HTTP Call 1)
│ ├── Span (HTTP Call 2)
│ │ └── Span (Retry 1)
│ └── Span (Cache)
│
└── Context
├── Trace ID: abc123
└── Span ID: xyz789
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
# Initialize tracing
provider = TracerProvider()
processor = BatchSpanProcessor(
JaegerExporter(
agent_host_name="jaeger",
agent_port=6831,
)
)
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Instrument Flask
FlaskInstrumentor().instrument_app(app)
RequestsInstrumentor().instrument()
# Create custom spans
tracer = trace.get_tracer(__name__)
def process_order(order_id):
with tracer.start_as_current_span("process_order") as span:
span.set_attribute("order.id", order_id)
# Database call
with tracer.start_as_current_span("db.save") as span:
span.set_attribute("db.system", "postgresql")
save_order(order_id)
# External API call
with tracer.start_as_current_span("http.payment") as span:
span.set_attribute("http.method", "POST")
span.set_attribute("http.url", "https://api.payment.com/charge")
call_payment_api(order_id)
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: jaeger
spec:
strategy: all-in-one
collector:
maxTraces: 100000
resources:
limits:
cpu: 500m
memory: 512Mi
query:
options:
basePath: /jaeger
storage:
type: elasticsearch
elasticsearch:
nodeCount: 3
redundancyPolicy: SingleRedundancy
// Spring Boot with Zipkin
@SpringBootApplication
@EnableZipkinTracer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
// Service discovery with Eureka
@Bean
public Brave brave() {
return Brave.Builder("my-service")
.spanReporter(zipkin)
.build();
}
@Bean
public Tracer tracer(Brave brave) {
return brave;
}
# Jaeger query
service = user-api
operation = /api/users
limit = 20
# Filter by tags
http.method = GET
http.status_code = 200
error = true
# Time range
start = 2024-01-15T10:00:00Z
end = 2024-01-15T10:30:00Z
# Manual context propagation
from opentelemetry import trace
def call_downstream_service(url, headers):
# Extract context from incoming request
ctx = trace.get_current_span().get_context()
# Inject context into headers
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("call_downstream") as span:
# Add downstream span to trace
carrier = {}
trace.propagation.inject(span.get_context(), carrier)
# Make HTTP call with propagated context
response = requests.get(
url,
headers={**headers, **carrier}
)
return response
# Analyze traces for performance
class TraceAnalyzer:
def __init__(self, jaeger_client):
self.client = jaeger_client
def find_slow_traces(self, threshold_ms=1000):
return self.client.query(
service='api',
lookback='1h',
min_duration=threshold_ms * 1000 # microseconds
)
def analyze_bottlenecks(self, service):
spans = self.client.get_service_spans(service)
# Group by operation
by_operation = defaultdict(list)
for span in spans:
by_operation[span.operation_name].append(span)
# Calculate average duration per operation
results = {}
for op, spans in by_operation.items():
avg_duration = sum(s.duration for s in spans) / len(spans)
results[op] = avg_duration
return sorted(results.items(), key=lambda x: x[1], reverse=True)
def find_error_patterns(self):
return self.client.query(
service='api',
tag={: }
)