rkhachatryan commented on code in PR #23845:
URL: https://github.com/apache/flink/pull/23845#discussion_r1417895747


##########
flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporter.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.traces.slf4j;
+
+import org.apache.flink.metrics.MetricConfig;
+import org.apache.flink.traces.Span;
+import org.apache.flink.traces.reporter.TraceReporter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link TraceReporter} that exports {@link org.apache.flink.traces.Span 
Spans} via SLF4J {@link
+ * Logger}.
+ */
+public class Slf4jTraceReporter implements TraceReporter {
+    private static final Logger LOG = 
LoggerFactory.getLogger(Slf4jTraceReporter.class);
+
+    @Override
+    public void notifyOfAddedSpan(Span span) {
+        StringBuilder builder = new StringBuilder();
+        builder.append("Reported span: ");
+        builder.append(span.toString());
+        LOG.info(builder.toString());

Review Comment:
   Why can't we just pass `builder` to `LOG`?
   ```
   LOG.info("Reported span: {}", builder);
   ```
   
   That should allow to eliminate `toString` call at runtime depending on the 
configuration.



##########
docs/content/docs/deployment/config.md:
##########
@@ -289,6 +289,15 @@ Enabling RocksDB's native metrics may cause degraded 
performance and should be s
 ----
 ----
 
+# Traces

Review Comment:
   NIT: This doesn't show up in TOC - it should be 2 or more `#` with the 
current settings.
   
   As well as other, existing section (e.g. `History Server` is missing).
   
   Settings can be fixed by adding to `docs/config.toml`:
   ```
   [markup.tableOfContents]
   startLevel = 1
   ```
   Not sure if this change would be reasonable and whether it can be added as a 
hotfix to this PR.



##########
docs/content/docs/ops/traces.md:
##########
@@ -0,0 +1,128 @@
+---
+title: "Traces"
+weight: 6
+type: docs
+aliases:
+  - /ops/traces.html
+  - /apis/traces.html
+  - /monitoring/traces.html
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Traces
+
+Flink exposes a tracing system that allows gathering and exposing traces to 
external systems.
+
+## Reporting traces
+
+You can access the tracing system from any user function that extends 
[RichFunction]({{< ref "docs/dev/datastream/user_defined_functions" 
>}}#rich-functions) by calling `getRuntimeContext().getMetricGroup()`.
+This method returns a `MetricGroup` object via which you can report a new 
single span trace.
+
+### Reporting single Span
+
+
+A `Span` represents something that happened in Flink at certain point of time, 
that will be reported to a `TraceReporter`.
+To report a `Span` you can use the `MetricGroup#addSpan(SpanBuilder)` method.
+
+Currently we don't support traces with multiple spans. Each `Span` is 
self-contained and represents things like a checkpoint or recovery.
+{{< tabs "9612d275-bdda-4322-a01f-ae6da805e917" >}}
+{{< tab "Java" >}}
+```java
+public class MyClass {
+    void doSomething() {
+        // (...)
+        metricGroup.addSpan(
+                Span.builder(MyClass.class, "SomeAction")
+                        .setStartTsMillis(startTs) // Optional
+                        .setEndTsMillis(endTs) // Optional
+                        .setAttribute("foo", "bar");
+    }
+}
+```
+{{< /tab >}}
+{{< tab "Python" >}}
+```python
+Currently reporting Spans from Python is not supported.
+```
+{{< /tab >}}
+{{< /tabs >}}
+
+## Reporter
+
+For information on how to set up Flink's trace reporters please take a look at 
the [trace reporters documentation]({{< ref "docs/deployment/trace_reporters" 
>}}).
+
+## System traces
+
+Flink reports traces listed below.
+
+The tables below generally feature 5 columns:
+
+* The "Scope" column describes what is that trace reported scope.
+
+* The "Name" column describes the name of the reported trace.
+
+* The "Attributes" column lists the names of all attributes that are reported 
with the given trace.
+
+* The "Description" column provides information as to what a given attribute 
is reporting.
+
+### Checkpointing
+
+Flink is reporting a single span trace for the whole checkpoint once 
checkpoint reaches a terminal state: COMPLETED or FAILED.

Review Comment:
   NIT: "Flink report a single span" ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to