|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +import os |
| 16 | +import threading |
15 | 17 | import urllib.parse
|
| 18 | +from enum import Enum |
16 | 19 | from re import escape, sub
|
17 | 20 | from typing import Dict, Sequence
|
18 | 21 |
|
@@ -152,3 +155,60 @@ def _python_path_without_directory(python_path, directory, path_separator):
|
152 | 155 | "",
|
153 | 156 | python_path,
|
154 | 157 | )
|
| 158 | + |
| 159 | + |
| 160 | +_OTEL_SEMCONV_STABILITY_OPT_IN_KEY = "OTEL_SEMCONV_STABILITY_OPT_IN" |
| 161 | + |
| 162 | + |
| 163 | +class _OpenTelemetryStabilitySignalType: |
| 164 | + HTTP = "http" |
| 165 | + |
| 166 | + |
| 167 | +class _OpenTelemetryStabilityMode(Enum): |
| 168 | + # http - emit the new, stable HTTP and networking conventions ONLY |
| 169 | + HTTP = "http" |
| 170 | + # http/dup - emit both the old and the stable HTTP and networking conventions |
| 171 | + HTTP_DUP = "http/dup" |
| 172 | + # default - continue emitting old experimental HTTP and networking conventions |
| 173 | + DEFAULT = "default" |
| 174 | + |
| 175 | + |
| 176 | +class _OpenTelemetrySemanticConventionStability: |
| 177 | + _initialized = False |
| 178 | + _lock = threading.Lock() |
| 179 | + _OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING = {} |
| 180 | + |
| 181 | + @classmethod |
| 182 | + def _initialize(cls): |
| 183 | + with _OpenTelemetrySemanticConventionStability._lock: |
| 184 | + if not _OpenTelemetrySemanticConventionStability._initialized: |
| 185 | + # Users can pass in comma delimited string for opt-in options |
| 186 | + # Only values for http stability are supported for now |
| 187 | + opt_in = os.environ.get(_OTEL_SEMCONV_STABILITY_OPT_IN_KEY, "") |
| 188 | + opt_in_list = [] |
| 189 | + if opt_in: |
| 190 | + opt_in_list = [s.strip() for s in opt_in.split(",")] |
| 191 | + http_opt_in = _OpenTelemetryStabilityMode.DEFAULT |
| 192 | + if opt_in_list: |
| 193 | + # Process http opt-in |
| 194 | + # http/dup takes priority over http |
| 195 | + if ( |
| 196 | + _OpenTelemetryStabilityMode.HTTP_DUP.value |
| 197 | + in opt_in_list |
| 198 | + ): |
| 199 | + http_opt_in = _OpenTelemetryStabilityMode.HTTP_DUP |
| 200 | + elif _OpenTelemetryStabilityMode.HTTP.value in opt_in_list: |
| 201 | + http_opt_in = _OpenTelemetryStabilityMode.HTTP |
| 202 | + _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING[ |
| 203 | + _OpenTelemetryStabilitySignalType.HTTP |
| 204 | + ] = http_opt_in |
| 205 | + _OpenTelemetrySemanticConventionStability._initialized = True |
| 206 | + |
| 207 | + @classmethod |
| 208 | + def _get_opentelemetry_stability_opt_in( |
| 209 | + type: _OpenTelemetryStabilitySignalType, |
| 210 | + ) -> _OpenTelemetryStabilityMode: |
| 211 | + with _OpenTelemetrySemanticConventionStability._lock: |
| 212 | + return _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING.get( |
| 213 | + type, _OpenTelemetryStabilityMode.DEFAULT |
| 214 | + ) |
0 commit comments