Logfire-Beispiel, das sich mit SigNoz statt mit Logfire verbindet
Das folgende Skript ist ein Testskript zur Verwendung der Logfire-Bibliothek, um Traces an eine SigNoz-Instanz statt an Logfires eigenes Backend zu senden. Es demonstriert, wie man Umgebungsvariablen für den OpenTelemetry-Protocol-(OTLP)-Exporter einrichtet, um auf einen SigNoz-Endpunkt zu zeigen, und wie man verschachtelte Spans erstellt, um verschiedene Teile einer hypothetischen Auftragsverarbeitungsfunktion zu verfolgen.
Für das SigNoz-Setup siehe Signoz standalone docker-compose with Traefik config.
logfire_signoz_example.py
#!/usr/bin/env python3
import os
import logfire
# Configure environment variables
os.environ['OTEL_EXPORTER_OTLP_ENDPOINT'] = 'https://http.signoz.mydomain.com/'
# Configure Logfire
logfire.configure(
send_to_logfire=False,
)
# Example function with nested spans
def process_order(order_id: str, user_id: str):
with logfire.span('validate_order'):
# Simulate validation
print(f"Validating order {order_id} for user {user_id}")
with logfire.span('process_payment'):
# Simulate payment processing
print(f"Processing payment for order {order_id}")
with logfire.span('call_payment_gateway'):
# Nested span example
print("Calling payment gateway API")
with logfire.span('fulfill_order'):
# Simulate order fulfillment
print(f"Fulfilling order {order_id}")
# Main execution
if __name__ == '__main__':
with logfire.span('main'):
process_order('12345', 'user-67890')So sieht es in SigNoz aus:

Check out similar posts by category:
Python, Monitoring
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow