تتبّع Micrometer
جهّز الخدمات باستخدام معرّفات التتبّع والمقاطع
تتبّع Micrometer درس مجاني في Spring Boot 4 Microservices & REST APIs على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Spring Boot 4 Microservices & REST APIs، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Spring Boot 4 Microservices & REST APIs 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Micrometer Tracing overview
Micrometer Tracing is a vendor-neutral tracing facade. You code against its API, and a bridge (Brave or OpenTelemetry) does the real work and propagation.
Adding the dependencies
Add Micrometer Tracing plus a bridge. The Brave bridge is a common choice.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>Auto-configuration kicks in
With the bridge on the classpath, Spring Boot auto-configures a Tracer and instruments incoming requests and outbound HTTP clients. Many spans appear with zero code.
The Tracer bean
The Tracer is the entry point for working with spans manually. It is auto-configured and injectable.
@Service
public class OrderService {
private final Tracer tracer;
public OrderService(Tracer tracer) { this.tracer = tracer; }
}Creating a custom span
Wrap a meaningful unit of work in its own span to time it and see it in the trace.
Span span = tracer.nextSpan().name("calculate-price");
try (Tracer.SpanInScope ws = tracer.withSpan(span.start())) {
calculatePrice();
} finally {
span.end();
}@NewSpan and @SpanTag
For convenience, annotate a method with @NewSpan to wrap it in a span automatically, and tag arguments with @SpanTag.
@NewSpan("load-customer")
public Customer load(@SpanTag("customerId") Long id) {
return repo.findById(id);
}Adding tags and events
Enrich spans with tags (key/value metadata) and events (timestamped notes) to make traces more diagnostic.
span.tag("user.id", userId);
span.event("cache-miss");Reading the current trace IDs
You can read the active trace and span IDs - useful for returning a trace id to clients or correlating.
Span current = tracer.currentSpan();
if (current != null) {
String traceId = current.context().traceId();
String spanId = current.context().spanId();
}Brave vs OpenTelemetry bridge
Two bridges exist: Brave (Zipkin-native) and OpenTelemetry (OTel ecosystem). Pick one - they should not be on the classpath together.
Propagation format
The bridge controls how context is propagated. You can choose formats like W3C (traceparent) or B3, which matters when integrating with other systems.
management:
tracing:
propagation:
type: w3cBaggage
Baggage is extra key/value data propagated alongside the trace context across services - e.g. a tenant id - so every downstream span and log can access it.
Quick Check
Check your Micrometer Tracing knowledge.
Recap
You used Micrometer Tracing:
- It is a facade; a Brave or OTel bridge does the real work
- Inject the
Tracerto create custom spans, or use@NewSpan - Add tags/events; read traceId/spanId
- Baggage propagates extra context
الأسئلة الشائعة
هل درس «تتبّع Micrometer» مجاني؟
نعم — نص درس «تتبّع Micrometer» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Spring Boot 4 Microservices & REST APIs، انتقل إلى CoddyKit PRO. تتضمن دورة Spring Boot 4 Microservices & REST APIs 4 دروس في المجموع.
ماذا ستتعلم في «تتبّع Micrometer»؟
جهّز الخدمات باستخدام معرّفات التتبّع والمقاطع تتمرن على Spring Boot 4 Microservices & REST APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Spring Boot 4 Microservices & REST APIs؟
لا تُشترط خبرة سابقة. Spring Boot 4 Microservices & REST APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تتبّع Micrometer»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Spring Boot 4 Microservices & REST APIs هذا؟
نعم. كل درس في Spring Boot 4 Microservices & REST APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.