build-tools icon indicating copy to clipboard operation
build-tools copied to clipboard

Semconv code generator example does not work for opentelemetry-specifications 1.14.0

Open marcalff opened this issue 2 years ago • 7 comments

Repo opentelemetry-cpp successfully used the semconv code generator already on 1.13.0 specs. See the generate script used:

generate.sh

Now trying to upgrade to 1.14.0 opentelemetry-specification:

SEMCONV_VERSION=1.14.0

The build fails with this error message:

opentelemetry.semconv.model.exceptions.ValidationError: Semantic Convention trace-exception reference `exception.type` but it cannot be found! - @2:5

In the 1.14.0 specs, indeed, file semantic_conventions/trace/trace-exception.yaml uses the exception defined in semantic_conventions/exception.yaml

Because the docker mount point used is semantic_conventions/trace/, the docker image does not see file exceptions.yaml

docker run --rm \
  -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source \
  ...

I hope this helps to narrow down the root cause. No idea about a fix however.

Please fix and adjust the example to work with the latest semantic conventions from the specs, as this is needed for each language SIG in general.

[resolved] Blocking for open-telemetry/opentelemetry-cpp#1671

marcalff avatar Oct 12 '22 19:10 marcalff

Have you tried just running it over everything, i.e. -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions without /trace? If you only want span conventions, I think you can use the --only span cmdline option (https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/src/opentelemetry/semconv/main.py#L211-L215)

Oberon00 avatar Oct 18 '22 11:10 Oberon00

Thanks @Oberon00

Adjusted the generation script to:

docker run --rm \
  -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \
  -v ${SCRIPT_DIR}/templates:/templates \
  -v ${ROOT_DIR}/api/include/opentelemetry/trace/:/output \
  otel/semconvgen:$GENERATOR_VERSION \
  --only span \
  -f /source code \
  --template /templates/SemanticAttributes.h.j2 \
  --output /output/semantic_conventions.h \
  -Dsemconv=trace \
  -Dclass=SemanticConventions \
  -DschemaUrl=$SCHEMA_URL \
  -Dnamespace_open="namespace trace {" \
  -Dnamespace_close="}"

and this now works for opentelemetry-cpp with 1.14.0 specs.

marcalff avatar Oct 18 '22 19:10 marcalff

--only span ends up removing attributes that are marked as type: event. Is there a way to get event and span types, without pulling in resource attributes?

jkwatson avatar Nov 11 '22 17:11 jkwatson

--only span ends up removing attributes that are marked as type: event. Is there a way to get event and span types, without pulling in resource attributes?

See https://github.com/open-telemetry/opentelemetry-java/pull/4938 for an example of what isn't working right.

jkwatson avatar Nov 11 '22 18:11 jkwatson

This is also happening in opentelemetry-dotnet when trying to update from semconv 1.13 to 1.17 when using generator versions 0.14.0, 0.15.0, and 0.15.1. Adding --only span didn't seem to work (I was still getting unexpected event.* attributes in the trace constants) but adding a mount for exception.yaml made the error go away.

  docker run --rm `
    -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source `
+   -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/exception.yaml:/source/exception.yaml `
    -v ${SCRIPT_DIR}/templates:/templates `
    -v ${ROOT_DIR}/Trace:/output `
    otel/semconvgen:$GENERATOR_VERSION

The result included some unexpected (to me) changes though.

See https://github.com/open-telemetry/opentelemetry-dotnet/pull/4102

ttd2089 avatar Jan 25 '23 02:01 ttd2089

Is this still a concern?

Oberon00 avatar Jun 27 '23 11:06 Oberon00

@Oberon00

Hi Christian,

As indicated on Oct 18, 2022, I was able to fix the opentelemetry-cpp generation scripts to make this work.

The documentation, however, was never updated, so yes, the instructions from the documentation do not work, which was the problem originally reported, and is still a concern.

Given that semantic conventions have migrated to their own repository, I would suggest to wait on the first release there, and then update the documentation with working instructions.

This will help every language repositories to adjust code generation scripts to the new code layout.

Related:

  • https://github.com/open-telemetry/semantic-conventions/issues/136
  • https://github.com/open-telemetry/semantic-conventions/issues/37

marcalff avatar Jun 28 '23 09:06 marcalff

obsolete

jsuereth avatar Jul 03 '24 14:07 jsuereth