Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update semantic conventions to v1.19 #965

Merged
merged 8 commits into from
Apr 26, 2023
Merged
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
26 changes: 26 additions & 0 deletions script/semantic-conventions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Semantic Convention generation script and templates

## Usage

To update semantic conventions, modify `semconv.sh`'s `SEMCONV_VERSION` and `GENERATOR_VERSION` values, then run:

```shell
./semconv.sh
```

## Backwards compatibility

If attributes have been removed in an update, you can add them back in via `templates/<class>_deprecations.php.partial` files,
the contents will be included in the generated output. Please remember to mark them as deprecated to discourage their future
use.

After generating new sementic conventions, you can locate removed attributes via:

```shell
diff <(grep "public const" src/SemConv/ResourceAttributes.php | sort -u) \
<(git show main:src/SemConv/ResourceAttributes.php | grep "public const" | sort -u) \
| grep '^>' \
| grep -v SCHEMA_URL
```

Use this output as a basis for updating the relevant deprecations file and generate a second time to include them in the final output.
42 changes: 8 additions & 34 deletions script/semantic-conventions/semconv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,81 +12,55 @@ SPEC_DIR="${ROOT_DIR}/var/opentelemetry-specification"
CODE_DIR="${ROOT_DIR}/src/SemConv"

# freeze the spec & generator tools versions to make SemanticAttributes generation reproducible
SEMCONV_VERSION=${SEMCONV_VERSION:=1.12.0}
SEMCONV_VERSION=${SEMCONV_VERSION:=1.19.0}
SPEC_VERSION=v$SEMCONV_VERSION
SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION
GENERATOR_VERSION=0.11.0
GENERATOR_VERSION=0.18.0

cd "${SCRIPT_DIR}" || exit

rm -rf "${SPEC_DIR}" || true
mkdir "${SPEC_DIR}"
cd "${SPEC_DIR}" || exit

git init
git init -b main
git remote add origin https://github.com/open-telemetry/opentelemetry-specification.git
git fetch origin "$SPEC_VERSION"
git reset --hard FETCH_HEAD

cd "${SCRIPT_DIR}" || exit

rm -rf "${CODE_DIR}" || true
mkdir -p "${CODE_DIR}"
git checkout HEAD "${CODE_DIR}/composer.json"
find "${CODE_DIR}" -name "*.php" -exec rm -f {} \;

# Trace
docker run --rm \
-v "${SPEC_DIR}/semantic_conventions/trace:/source" \
-v "${SPEC_DIR}/semantic_conventions:/source" \
-v "${SCRIPT_DIR}/templates:/templates" \
-v "${CODE_DIR}:/output" \
-u "${UID}" \
otel/semconvgen:$GENERATOR_VERSION \
--only span,event,attribute_group,scope \
-f /source code \
--template /templates/Attributes.php.j2 \
--output "/output/TraceAttributes.php" \
-Dnamespace="OpenTelemetry\\SemConv" \
-Dclass="Trace" \
-DschemaUrl=$SCHEMA_URL

docker run --rm \
-v "${SPEC_DIR}/semantic_conventions/trace:/source" \
-v "${SCRIPT_DIR}/templates:/templates" \
-v "${CODE_DIR}:/"output \
-u "${UID}" \
otel/semconvgen:$GENERATOR_VERSION \
-f /source code \
--template /templates/AttributeValues.php.j2 \
--output "/output/TraceAttributeValues.php" \
-Dnamespace="OpenTelemetry\\SemConv" \
-Dclass="Trace" \
-DschemaUrl=$SCHEMA_URL


# Resource
docker run --rm \
-v "${SPEC_DIR}/semantic_conventions/resource:/source" \
-v "${SPEC_DIR}/semantic_conventions:/source" \
-v "${SCRIPT_DIR}/templates:/templates" \
-v "${CODE_DIR}:/output" \
-u "${UID}" \
otel/semconvgen:$GENERATOR_VERSION \
--only resource \
-f /source code \
--template /templates/Attributes.php.j2 \
--output "/output/ResourceAttributes.php" \
-Dnamespace="OpenTelemetry\\SemConv" \
-Dclass="Resource" \
-DschemaUrl=$SCHEMA_URL

docker run --rm \
-v "${SPEC_DIR}/semantic_conventions/resource:/source" \
-v "${SCRIPT_DIR}/templates:/templates" \
-v "${CODE_DIR}:/output" \
-u "${UID}" \
otel/semconvgen:$GENERATOR_VERSION \
-f /source code \
--template /templates/AttributeValues.php.j2 \
--output "/output/ResourceAttributeValues.php" \
-Dnamespace="OpenTelemetry\\SemConv" \
-Dclass="Resource" \
-DschemaUrl=$SCHEMA_URL

rm -rf "${SPEC_DIR}" || true
8 changes: 5 additions & 3 deletions script/semantic-conventions/templates/Attributes.php.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ interface {{ class }}Attributes
*
* {{ attribute.note | render_markdown(code="`{0}`", paragraph="{0}", link="{1}") | trim("\n")| regex_replace(pattern="\n", replace="\n * ") }}
{%- endif %}
{%- if attribute.examples or attribute.deprecated %}
{%- if attribute.examples or attribute.stability == "deprecated" %}
*
{%- if attribute.deprecated %}
* @deprecated {{ attribute.deprecated | render_markdown(code="`{0}`", paragraph="{0}", link="{{@link {0} {1}}}") | regex_replace(pattern="\n", replace="\n * ") }}
{%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %}
* @deprecated {{attribute.brief}}.
{%- endif %}
{%- for example in attribute.examples if example %}
* @example {{ example }}
Expand All @@ -32,5 +32,7 @@ interface {{ class }}Attributes
public const {{ attribute.fqn | to_const_name }} = '{{ attribute.fqn }}';
{% if not loop.last %}{# blank line #}{% endif %}
{%- endfor -%}
{# add our own deprecations for moved/removed attributes, so we don't break things #}
{% include class|lower + "_deprecations.php.partial" ignore missing without context %}
}
{# blank line #}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @deprecated
*/
public const BROWSER_USER_AGENT = 'browser.user_agent';

/**
* @deprecated
*/
public const FAAS_ID = 'faas.id';
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @deprecated
*/
public const FAAS_EXECUTION = 'faas.execution';

/**
* @deprecated
*/
public const HTTP_HOST = 'http.host';

/**
* @deprecated
*/
public const HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = 'http.request_content_length_uncompressed';

/**
* @deprecated
*/
public const HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED = 'http.response_content_length_uncompressed';

/**
* @deprecated
*/
public const HTTP_RETRY_COUNT = 'http.retry_count';

/**
* @deprecated
*/
public const HTTP_SERVER_NAME = 'http.server_name';

/**
* @deprecated
*/
public const HTTP_USER_AGENT = 'http.user_agent';

/**
* @deprecated
*/
public const MESSAGING_CONVERSATION_ID = 'messaging.conversation_id';

/**
* @deprecated
*/
public const MESSAGING_DESTINATION = 'messaging.destination';

/**
* @deprecated
*/
public const MESSAGING_KAFKA_PARTITION = 'messaging.kafka.partition';

/**
* @deprecated
*/
public const MESSAGING_KAFKA_TOMBSTONE = 'messaging.kafka.tombstone';

/**
* @deprecated
*/
public const MESSAGING_PROTOCOL = 'messaging.protocol';

/**
* @deprecated
*/
public const MESSAGING_PROTOCOL_VERSION = 'messaging.protocol_version';

/**
* @deprecated
*/
public const MESSAGING_RABBITMQ_ROUTING_KEY = 'messaging.rabbitmq.routing_key';

/**
* @deprecated
*/
public const MESSAGING_TEMP_DESTINATION = 'messaging.temp_destination';

/**
* @deprecated
*/
public const MESSAGING_URL = 'messaging.url';

/**
* @deprecated
*/
public const NET_HOST_IP = 'net.host.ip';

/**
* @deprecated
*/
public const NET_PEER_IP = 'net.peer.ip';
3 changes: 1 addition & 2 deletions src/API/Trace/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OpenTelemetry\API\Trace;

use Closure;
use OpenTelemetry\SemConv\TraceAttributes;
use Throwable;

/**
Expand Down Expand Up @@ -35,7 +34,7 @@ function trace(SpanInterface $span, Closure $closure, iterable $args = [])
return $c(...$a, ...($a = []));
} catch (Throwable $e) {
$s->setStatus(StatusCode::STATUS_ERROR, $e->getMessage());
$s->recordException($e, [TraceAttributes::EXCEPTION_ESCAPED => true]);
$s->recordException($e, ['exception.escaped' => true]);

throw $e;
} finally {
Expand Down
1 change: 0 additions & 1 deletion src/API/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"require": {
"php": "^7.4 || ^8.0",
"open-telemetry/context": "^1.0",
"open-telemetry/sem-conv": "^1.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
Expand Down
10 changes: 10 additions & 0 deletions src/SemConv/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# OpenTelemetry Semantic Conventions

Common semantic conventions used by OpenTelemetry implementations across all languages.

See https://opentelemetry.io/docs/concepts/semantic-conventions/.

## Installation

```shell
composer require open-telemetry/sem-conv
```
Loading