Skip to content
OpenClaw 不踩坑恶意 Skills ,企业需 Skills Registry:Nacos 3.2 发布Know more

Tracing

Tracing Plugin

The Nacos Trace plugin subscribes to internal Nacos resource operation events for audit, troubleshooting, and diagnostics. It records Nacos domain events such as service registration, service push, instance health changes, and AI resource operations.

It is not distributed tracing between application services. If you need request spans across business services, use OpenTelemetry, SkyWalking, Zipkin, or another distributed tracing system.

Use Cases

  • Record Naming events such as service registration, deregistration, subscription, and push.
  • Record instance health change reasons to troubleshoot unstable instances.
  • Send Nacos resource operation events to logs, audit systems, or observability backends.
  • Subscribe to AI resource lifecycle events for audit records of publish, online/offline, delete, and similar operations.

Event Model

A Trace plugin implements NacosTraceSubscriber. During startup, Nacos loads subscribers through SPI and dispatches only the event types declared by each subscriber.

ConceptDescription
TraceEventBase trace event. It contains event type, event time, namespace, group, and resource name.
Domain eventA subclass of TraceEvent, such as Naming events and AI resource events.
SubscriberPlugin-provided event consumer. It receives only the event classes it subscribes to.
executor()Optional executor. If non-null, Nacos uses it to call onEvent().

Current Events

Naming events:

Event classEvent typeMeaning
RegisterInstanceTraceEventREGISTER_INSTANCE_TRACE_EVENTInstance registration.
BatchRegisterInstanceTraceEventBATCH_REGISTER_INSTANCE_TRACE_EVENTBatch instance registration.
DeregisterInstanceTraceEventDEREGISTER_INSTANCE_TRACE_EVENTInstance deregistration.
RegisterServiceTraceEventREGISTER_SERVICE_TRACE_EVENTEmpty service creation.
DeregisterServiceTraceEventDEREGISTER_SERVICE_TRACE_EVENTEmpty service deletion.
UpdateInstanceTraceEventUPDATE_INSTANCE_TRACE_EVENTInstance metadata or state update.
UpdateServiceTraceEventUPDATE_SERVICE_TRACE_EVENTService metadata update.
SubscribeServiceTraceEventSUBSCRIBE_SERVICE_TRACE_EVENTService subscription.
UnsubscribeServiceTraceEventUNSUBSCRIBE_SERVICE_TRACE_EVENTService unsubscription.
PushServiceTraceEventPUSH_SERVICE_TRACE_EVENTPush service data to subscribers.
HealthStateChangeTraceEventHEALTH_STATE_CHANGE_TRACE_EVENTInstance health state change.

AI resource events:

Event classEvent typeMeaning
AiResourceTraceEventAI_RESOURCE_TRACE_EVENTAI resource lifecycle operation, such as create, review, publish, online/offline, delete, tag update, and scope update.

DeregisterInstanceTraceEvent carries a deregistration reason. Common values include REQUEST, NATIVE_DISCONNECTED, SYNCED_DISCONNECTED, and HEARTBEAT_EXPIRE.

Nacos provides a default AI resource Trace log subscriber. It writes AiResourceTraceEvent records to ai-resource-trace.log for AI resource audit compatibility.

Enable a Plugin

Put the plugin JAR under ${nacos.home}/plugins, or add it to the Nacos Server startup classpath. The plugin implementation must be declared in META-INF/services/com.alibaba.nacos.plugin.trace.spi.NacosTraceSubscriber.

After startup, check ${nacos.home}/logs/nacos.log for the loading log:

[TracePluginManager] Load NacosTraceSubscriber(...) name(...) successfully.

Starting from Nacos 3.2, Trace plugins are also exposed to unified plugin management with plugin type trace. If a Trace plugin is disabled, Nacos no longer dispatches events to that subscriber.

Develop a Plugin

Add the dependency:

<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-trace-plugin</artifactId>
<version>${project.version}</version>
</dependency>

Implement com.alibaba.nacos.plugin.trace.spi.NacosTraceSubscriber:

MethodDescription
getName()Stable subscriber name. A later subscriber with the same name replaces an earlier one.
subscribeTypes()Event classes this subscriber wants to receive.
onEvent(event)Handle the event.
executor()Optional executor. Return a dedicated executor for slow IO.

Minimal example:

public class NamingAuditTraceSubscriber implements NacosTraceSubscriber {
@Override
public String getName() {
return "naming-audit";
}
@Override
public List<Class<? extends TraceEvent>> subscribeTypes() {
return Collections.singletonList(RegisterInstanceTraceEvent.class);
}
@Override
public void onEvent(TraceEvent event) {
// Write audit log or send to an observability backend.
}
}

Degradation and Stability

The Trace publisher dispatches events through a queue. Under pressure, Nacos may drop new Trace events to protect server stability. When this happens, logs contain a message similar to:

Trace Event Publish failed, event : ..., publish queue size : ...

Production advice:

  • Use an independent Executor when writing to remote systems, files, databases, or message queues.
  • Configure timeouts, rate limits, and failure handling for external sinks.
  • Do not modify Nacos resources inside onEvent().
  • Do not write sensitive information to Trace logs.
  • Dropped Trace events mean observability data is incomplete. They do not mean the main Nacos flow failed.

Troubleshooting

SymptomWhat to check
Plugin receives no eventsCheck the JAR, META-INF/services, getName(), and subscribeTypes().
Event handling blocksCheck whether onEvent() performs slow IO. Implement executor() if needed.
Logs contain Trace Event Publish failedTrace queue pressure is high. Check subscriber processing speed and external sinks.
Same-name plugins behave unexpectedlyCheck whether multiple subscribers return the same getName().