Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flexmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-util-visitor</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vladsch.flexmark.util.sequence.Escaping;
import com.vladsch.flexmark.util.sequence.LineAppendable;
import com.vladsch.flexmark.util.sequence.TagRange;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -203,6 +204,7 @@ public void render(@NotNull Node node, @NotNull Appendable output) {
* @param node node to render
* @param output appendable to use for the output
*/
@WithSpan("markdown.render")
public void render(@NotNull Node node, @NotNull Appendable output, int maxTrailingBlankLines) {
HtmlWriter htmlWriter = new HtmlWriter(output, htmlOptions.indentSize, htmlOptions.formatFlags, !htmlOptions.htmlBlockOpenTagEol, !htmlOptions.htmlBlockCloseTagEol);
MainNodeRenderer renderer = new MainNodeRenderer(options, htmlWriter, node.getDocument());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.vladsch.flexmark.util.sequence.BasedSequence;
import com.vladsch.flexmark.util.sequence.ReplacedBasedSequence;
import com.vladsch.flexmark.util.sequence.mappers.SpecialLeadInHandler;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -353,6 +354,7 @@ public static Builder builder(DataHolder options) {
* @param input the text to parse
* @return the root node
*/
@WithSpan("markdown.parse")
public @NotNull Document parse(@NotNull BasedSequence input) {
// NOTE: parser can only handle contiguous sequences with no out of base characters
if (input instanceof ReplacedBasedSequence) {
Expand All @@ -379,6 +381,7 @@ public static Builder builder(DataHolder options) {
* @param input the text to parse
* @return the root node
*/
@WithSpan("markdown.parse")
public @NotNull Document parse(@NotNull String input) {
DocumentParser documentParser = new DocumentParser(options
, blockParserFactories
Expand All @@ -398,6 +401,7 @@ public static Builder builder(DataHolder options) {
* @return the root node
* @throws IOException when reading throws an exception
*/
@WithSpan("markdown.parse")
public @NotNull Document parseReader(@NotNull Reader input) throws IOException {
DocumentParser documentParser = new DocumentParser(options
, blockParserFactories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vladsch.flexmark.util.misc.CharPredicate;
import com.vladsch.flexmark.util.sequence.BasedSequence;
import com.vladsch.flexmark.util.sequence.PrefixedSubSequence;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.jetbrains.annotations.NotNull;

import java.io.BufferedReader;
Expand Down Expand Up @@ -271,16 +272,23 @@ public InlineParser getInlineParser() {
*/
public Document parse(CharSequence source) {
BasedSequence input = BasedSequence.of(source);
int lineStart = 0;
int lineBreak;
int lineEOL;
int lineEnd;
lineNumber = 0;

documentBlockParser.initializeDocument(options, input);
inlineParser.initializeDocument(documentBlockParser.getBlock());

currentPhase = ParserPhase.PARSE_BLOCKS;
parseBlocks(input);

return finalizeAndProcess();
}

@WithSpan("markdown.parse.blocks")
private void parseBlocks(BasedSequence input) {
int lineStart = 0;
int lineBreak;
int lineEOL;
int lineEnd;

while ((lineBreak = Parsing.findLineBreak(input, lineStart)) != -1) {
BasedSequence line = input.subSequence(lineStart, lineBreak);
Expand Down Expand Up @@ -308,8 +316,6 @@ public Document parse(CharSequence source) {
incorporateLine(lineWithEOL);
lineNumber++;
}

return finalizeAndProcess();
}

public Document parse(Reader input) throws IOException {
Expand Down Expand Up @@ -745,6 +751,7 @@ private void finalize(BlockParser blockParser) {
/**
* Walk through a block & children recursively, parsing string content into inline content where appropriate.
*/
@WithSpan("markdown.parse.inlines")
private void processInlines() {
for (BlockParser blockParser : blockTracker.allBlockParsers()) {
blockParser.parseInlines(inlineParser);
Expand Down Expand Up @@ -938,6 +945,7 @@ private void preProcessParagraph(Paragraph block, List<ParagraphPreProcessorFact
}
}

@WithSpan("markdown.parse.pre_process_paragraphs")
private void preProcessParagraphs() {
// here we run preProcessing stages
if (blockTracker.getNodeClassifier().containsCategory(Paragraph.class)) {
Expand All @@ -951,6 +959,7 @@ private void preProcessParagraphs() {
}
}

@WithSpan("markdown.parse.pre_process_blocks")
private void preProcessBlocks() {
// here we run preProcessing stages
HashSet<Class<?>> blockTypes = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.vladsch.flexmark.util.dependency.DependencyResolver;
import com.vladsch.flexmark.util.dependency.DependentItem;
import com.vladsch.flexmark.util.dependency.DependentItemMap;
import io.opentelemetry.instrumentation.annotations.WithSpan;

import java.util.*;

Expand Down Expand Up @@ -50,6 +51,7 @@ public static List<PostProcessorDependencyStage> calculatePostProcessors(DataHol
return dependencyStages;
}

@WithSpan("markdown.parse.post_process")
public static Document processDocument(Document document, List<PostProcessorDependencyStage> processorDependencies) {
if (!processorDependencies.isEmpty()) {
PostProcessorManager manager = new PostProcessorManager(processorDependencies);
Expand Down
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,15 @@
<version>${project.version}</version>
</dependency>

<!-- Annotation-only dependency, spans are created by a Java agent
(dd-java-agent with dd.trace.otel.enabled=true, or opentelemetry-javaagent).
Inert without an agent. -->
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>2.16.0</version>
</dependency>

<!-- Common test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
Loading