Skip to content

Commit

Permalink
Use context_diff over custom function
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesjj committed Mar 5, 2024
1 parent 1bdd500 commit 215081f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions semantic-conventions/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ RUN apk --update add --virtual build-dependencies build-base \
&& pip install -U ./semconvgen-*.whl \
&& apk del build-dependencies \
&& rm *.whl
ENV COLORED_DIFF true
ENTRYPOINT ["gen-semconv"]
3 changes: 3 additions & 0 deletions semantic-conventions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ The image also supports customising
[Whitespace Control in Jinja templates](https://jinja.palletsprojects.com/en/3.1.x/templates/#whitespace-control)
via the additional flag `--trim-whitespace`. Providing the flag will enable both `lstrip_blocks` and `trim_blocks`.

### Enabling/disabling support for colored diffs in error messages
The `COLORED_DIFF` environment variable is set in the `semantic-conventions` `Dockerfile`. When this environment varibale is set, errors related to reformatting tables will show a "colored diff" using standard ANSI control characters. While this should be supported natively in any modern terminal environment, you may unset this variable if issues arise. Doing so will enable a "fall back" of non-colored inline diffs showing what was "added" and what was "removed", followed by the exact tokens added/removed encased in single quotes.

## Version compatibility check

You can check compatibility between the local one specified with `--yaml-root` and sepcific OpenTelemetry semantic convention version using the following command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
)
from opentelemetry.semconv.model.utils import ID_RE
from opentelemetry.semconv.templating.markdown.options import MarkdownOptions

from .utils import VisualDiffer

_REQUIREMENT_LEVEL_URL = (
Expand Down Expand Up @@ -393,12 +394,11 @@ def render_md(self):
output = io.StringIO()
self._render_single_file(content, md_filename, output)
if self.options.check_only:
if content != output.getvalue():
sys.exit(
"File "
+ md_filename
+ " contains a table that would be reformatted."
)
output_value = output.getvalue()
if content != output_value:
diff = VisualDiffer.visual_diff(content, output_value)
err_msg = f"File {md_filename} contains a table that would be reformatted.\n{diff}"
sys.exit(err_msg)
else:
with open(md_filename, "w", encoding="utf-8") as md_file:
md_file.write(output.getvalue())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TestTable

**Status**: [Experimental](../../../document-status.md)

**type:** `foo.bar`

**Description:** Test case

<!-- semconv redis -->

| Attribute  | Type | Description  | Examples | Requirement Level |
| --------- | ------ | ------------ | -------- | ----------------- |
| `foo.bar.foo` | string | Lorem Ipsumz | no | Recommended |

<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TestTable

**Status**: [Experimental](../../../document-status.md)

**type:** `foo.bar`

**Description:** Test case

<!-- semconv redis -->

| Atribute | Type | Description | Examples | Requirement Level |
| --------- | ------ | ----------- | -------- | ----------------- |
| `bar.foo` | string | Lorem Ipsum | no | Recommended |

<!-- endsemconv -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TestTable

**Status**: [Experimental](../../../document-status.md)

**type:** `foo.bar`

**Description:** Test case

<!-- semconv redis -->

| Attribute | Type | Description | Examples | Requirement Level |
| --------- | ------ | ------------ | -------- | ----------------- |
| `foo.bar` | string | Lorem Ipsumz | no | Recommended |

<!-- endsemconv -->
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import unittest
from pathlib import Path
from typing import Optional, Sequence
from unittest.mock import patch

from opentelemetry.semconv.model.semantic_convention import SemanticConventionSet
from opentelemetry.semconv.templating.markdown import MarkdownRenderer
from opentelemetry.semconv.templating.markdown import MarkdownRenderer, VisualDiffer
from opentelemetry.semconv.templating.markdown.options import MarkdownOptions


Expand Down

0 comments on commit 215081f

Please sign in to comment.