internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: open-telemetry/opentelemetry-python

Issue:
Move getting started guide to opentelemetry.io
For GA there is an ask to add at least all getting started documentation to the opentelemetry.io website -- for Python this is tracked in: https://github.com/open-telemetry/opentelemetry.io/issues/285. Maintaining the documentation in two places is not ideal so proposal is to move getting started documentation. A similar activity already happened for Java.


Discussion:
@flands I did the JS one recently, I can also take care of this one. If I see this right what needs to be done is taking https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html and transferring the pages over to opentelemetry.io ?
This issue was marked stale due to lack of activity. It will be closed in 30 days.

Resolving patch:
diff --git a/docs/getting_started/otlpcollector_example.py b/docs/getting_started/otlpcollector_example.py
--- a/docs/getting_started/otlpcollector_example.py
+++ b/docs/getting_started/otlpcollector_example.py
@@ -24,7 +24,7 @@
 
 span_exporter = OTLPSpanExporter(
     # optional
-    # endpoint:="myCollectorURL:55678",
+    # endpoint:="myCollectorURL:4317",
     # credentials=ChannelCredentials(credentials),
     # headers=(("metadata", "metadata")),
 )
diff --git a/docs/getting_started/tracing_example.py b/docs/getting_started/tracing_example.py
--- a/docs/getting_started/tracing_example.py
+++ b/docs/getting_started/tracing_example.py
@@ -20,10 +20,11 @@
     SimpleSpanProcessor,
 )
 
-trace.set_tracer_provider(TracerProvider())
-trace.get_tracer_provider().add_span_processor(
-    SimpleSpanProcessor(ConsoleSpanExporter())
-)
+provider = TracerProvider()
+processor = SimpleSpanProcessor(ConsoleSpanExporter())
+provider.add_span_processor(processor)
+trace.set_tracer_provider(provider)
+
 
 tracer = trace.get_tracer(__name__)
 


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
Documentation references old propagators module
`propagators.inject` is being used [here](https://github.com/open-telemetry/opentelemetry-python/blob/main/docs/examples/auto-instrumentation/client.py#L40), `propagators.extract` is being used [here](https://github.com/open-telemetry/opentelemetry-python/blame/main/docs/examples/auto-instrumentation/README.rst#L40). They should use `propagate` instead.


Discussion:

Resolving patch:
diff --git a/docs/examples/auto-instrumentation/client.py b/docs/examples/auto-instrumentation/client.py
--- a/docs/examples/auto-instrumentation/client.py
+++ b/docs/examples/auto-instrumentation/client.py
@@ -16,7 +16,8 @@
 
 from requests import get
 
-from opentelemetry import propagators, trace
+from opentelemetry import trace
+from opentelemetry.propagate import inject
 from opentelemetry.sdk.trace import TracerProvider
 from opentelemetry.sdk.trace.export import (
     ConsoleSpanExporter,
@@ -37,7 +38,7 @@
 
     with tracer.start_as_current_span("client-server"):
         headers = {}
-        propagators.inject(headers)
+        inject(headers)
         requested = get(
             "http://localhost:8082/server_request",
             params={"param": argv[1]},


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
OpenTelemetry distro as a default distro for OpenTelemetry Instrumentation
The `opentelemetry-instrumentation` auto instrumentation doesn't work without installing `opentelemetry-distro` as the components initialisation is done in distro package. How does a regular user know about this and shouldn't openetemetry distro be the default and can give an option to let user use others? 


Discussion:
This issue was marked stale due to lack of activity. It will be closed in 30 days.
Hey Folks, it is unclear from the docs to install distro, and many users must be missing this too. 

Resolving patch:
diff --git a/docs/getting_started/otlpcollector_example.py b/docs/getting_started/otlpcollector_example.py
--- a/docs/getting_started/otlpcollector_example.py
+++ b/docs/getting_started/otlpcollector_example.py
@@ -24,7 +24,7 @@
 
 span_exporter = OTLPSpanExporter(
     # optional
-    # endpoint:="myCollectorURL:4317",
+    # endpoint="myCollectorURL:4317",
     # credentials=ChannelCredentials(credentials),
     # headers=(("metadata", "metadata")),
 )


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
Every string character is being checked
As reported @yetanotherjsontodatabaseexporter in #1939, strings are also sequences. We are unnecessarily checking every character [here](https://github.com/open-telemetry/opentelemetry-python/blob/f11ed2f3bacb11d53a7a2b4837cf6308fa34cc71/opentelemetry-api/src/opentelemetry/attributes/__init__.py#L46).


Discussion:

Resolving patch:
diff --git a/opentelemetry-api/src/opentelemetry/attributes/__init__.py b/opentelemetry-api/src/opentelemetry/attributes/__init__.py
--- a/opentelemetry-api/src/opentelemetry/attributes/__init__.py
+++ b/opentelemetry-api/src/opentelemetry/attributes/__init__.py
@@ -17,7 +17,6 @@
 import threading
 from collections import OrderedDict
 from collections.abc import MutableMapping
-from types import MappingProxyType
 from typing import MutableSequence, Optional, Sequence
 
 from opentelemetry.util import types
@@ -38,9 +37,10 @@ def _is_valid_attribute_value(value: types.AttributeValue) -> bool:
             i.e. it MUST NOT contain values of different types.
     """
 
+    if isinstance(value, _VALID_ATTR_VALUE_TYPES):
+        return True
+
     if isinstance(value, Sequence):
-        if len(value) == 0:
-            return True
 
         sequence_first_valid_type = None
         for element in value:
@@ -69,16 +69,15 @@ def _is_valid_attribute_value(value: types.AttributeValue) -> bool:
                     type(element).__name__,
                 )
                 return False
-
-    elif not isinstance(value, _VALID_ATTR_VALUE_TYPES):
-        _logger.warning(
-            "Invalid type %s for attribute value. Expected one of %s or a "
-            "sequence of those types",
-            type(value).__name__,
-            [valid_type.__name__ for valid_type in _VALID_ATTR_VALUE_TYPES],
-        )
-        return False
-    return True
+        return True
+
+    _logger.warning(
+        "Invalid type %s for attribute value. Expected one of %s or a "
+        "sequence of those types",
+        type(value).__name__,
+        [valid_type.__name__ for valid_type in _VALID_ATTR_VALUE_TYPES],
+    )
+    return False
 
 
 def _filter_attributes(attributes: types.Attributes) -> None:


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
Use basename in eachdist.py
Related to [this](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/583).


Discussion:

Resolving patch:
diff --git a/scripts/eachdist.py b/scripts/eachdist.py
--- a/scripts/eachdist.py
+++ b/scripts/eachdist.py
@@ -11,6 +11,7 @@
 from datetime import datetime
 from inspect import cleandoc
 from itertools import chain
+from os.path import basename
 from pathlib import Path, PurePath
 
 DEFAULT_ALLSEP = " "
@@ -628,11 +629,10 @@ def update_version_files(targets, version, packages):
 def update_dependencies(targets, version, packages):
     print("updating dependencies")
     for pkg in packages:
-        package_name = pkg.split("/")[-1]
         update_files(
             targets,
             "setup.cfg",
-            r"({}.*)==(.*)".format(package_name),
+            r"({}.*)==(.*)".format(basename(pkg)),
             r"\1== " + version,
         )
 


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
Distros are coupled with instrumentations
As mentioned [here](https://github.com/open-telemetry/opentelemetry-python/discussions/2005#discussion-3489738).


Discussion:

Resolving patch:
diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
--- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
+++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
@@ -60,6 +60,9 @@ def _load_instrumentors(distro):
         # to handle users entering "requests , flask" or "requests, flask" with spaces
         package_to_exclude = [x.strip() for x in package_to_exclude]
 
+    for entry_point in iter_entry_points("opentelemetry_pre_instrument"):
+        entry_point.load()()
+
     for entry_point in iter_entry_points("opentelemetry_instrumentor"):
         if entry_point.name in package_to_exclude:
             logger.debug(
@@ -84,6 +87,9 @@ def _load_instrumentors(distro):
             logger.exception("Instrumenting of %s failed", entry_point.name)
             raise exc
 
+    for entry_point in iter_entry_points("opentelemetry_post_instrument"):
+        entry_point.load()()
+
 
 def _load_configurators():
     configured = None


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
The implementation of Trace ID is incompatible with the spec
**Describe your environment**

* OS: Linux (Debian 10)
* Python: 3.9.2 (vanilla)

**Steps to reproduce**
1. Read [the spec of Trace ID](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#spancontext)
2. Read [the implementation of Trace ID in SpanContext](https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/trace/span.py#L561)

**What is the expected behavior?**
Trace ID in OpenTelemetry for Python is defined as "16-bytes bytes" which is following OpenTelemetry's spec

**What is the actual behavior?**
Trace ID is just defined as `int` and there is no validation for the length of the ID in [the SpanContext constructor](https://github.com/open-telemetry/opentelemetry-python/blob/371eaa8e2d90fe418dbef163b65181736c8cfce3/opentelemetry-api/src/opentelemetry/trace/span.py#L410-L428).

**Additional context**
If we make OpenTelemetry for Python follow the existing spec as-is, it may be braking changes for existing libraries including 1st party and 3rd parties.

Some other languages are validating the length of data: 
* [Go](https://github.com/open-telemetry/opentelemetry-go/blob/main/trace/trace.go#L49)
* [Java](https://github.com/open-telemetry/opentelemetry-java/blob/main/api/all/src/main/java/io/opentelemetry/api/trace/TraceId.java#L60-L65)


Discussion:

Resolving patch:
diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py
--- a/opentelemetry-api/src/opentelemetry/trace/span.py
+++ b/opentelemetry-api/src/opentelemetry/trace/span.py
@@ -389,6 +389,7 @@ def values(self) -> typing.ValuesView[str]:
 
 
 DEFAULT_TRACE_STATE = TraceState.get_default()
+_TRACE_ID_HEX_LENGTH = 2 ** 128 - 1
 
 
 class SpanContext(
@@ -420,7 +421,11 @@ def __new__(
         if trace_state is None:
             trace_state = DEFAULT_TRACE_STATE
 
-        is_valid = trace_id != INVALID_TRACE_ID and span_id != INVALID_SPAN_ID
+        is_valid = (
+            trace_id != INVALID_TRACE_ID
+            and span_id != INVALID_SPAN_ID
+            and trace_id < _TRACE_ID_HEX_LENGTH
+        )
 
         return tuple.__new__(
             cls,


Test patch:
diff --git a/opentelemetry-api/tests/trace/test_span_context.py b/opentelemetry-api/tests/trace/test_span_context.py
--- a/opentelemetry-api/tests/trace/test_span_context.py
+++ b/opentelemetry-api/tests/trace/test_span_context.py
@@ -34,3 +34,12 @@ def test_span_context_pickle(self):
         pickle_sc = pickle.loads(pickle.dumps(sc))
         self.assertEqual(sc.trace_id, pickle_sc.trace_id)
         self.assertEqual(sc.span_id, pickle_sc.span_id)
+
+        invalid_sc = trace.SpanContext(
+            9999999999999999999999999999999999999999999999999999999999999999999999999999,
+            9,
+            is_remote=False,
+            trace_flags=trace.DEFAULT_TRACE_OPTIONS,
+            trace_state=trace.DEFAULT_TRACE_STATE,
+        )
+        self.assertFalse(invalid_sc.is_valid)
Repository: open-telemetry/opentelemetry-python

Issue:
Update OTLP HTTP port
As per spec change here:

https://github.com/open-telemetry/opentelemetry-specification/pull/1839

The OTLP HTTP port should be 4318.


Discussion:

Resolving patch:
diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py
--- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py
+++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py
@@ -47,7 +47,7 @@
 
 
 DEFAULT_COMPRESSION = Compression.NoCompression
-DEFAULT_ENDPOINT = "http://localhost:55681/v1/traces"
+DEFAULT_ENDPOINT = "http://localhost:4318/v1/traces"
 DEFAULT_TIMEOUT = 10  # in seconds
 
 


Test patch:
diff --git a/tests/opentelemetry-docker-tests/tests/docker-compose.yml b/tests/opentelemetry-docker-tests/tests/docker-compose.yml
--- a/tests/opentelemetry-docker-tests/tests/docker-compose.yml
+++ b/tests/opentelemetry-docker-tests/tests/docker-compose.yml
@@ -8,7 +8,7 @@ services:
         - "8888:8888"
         - "55678:55678"
   otcollector:
-    image: otel/opentelemetry-collector:0.22.0
+    image: otel/opentelemetry-collector:0.31.0
     ports:
         - "4317:4317"
-        - "55681:55681"
+        - "4318:55681"
Repository: open-telemetry/opentelemetry-python

Issue:
Update limits implementation to correctly deal with empty and negative values.
According to the [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#span-limits-)

> Empty value is treated as infinity. Non-integer and negative values are invalid.

We should ensure out limits implementation takes this into account. 


Discussion:

Resolving patch:
diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
--- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
@@ -67,7 +67,7 @@
 _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128
 
 
-_ENV_VALUE_UNSET = "unset"
+_ENV_VALUE_UNSET = ""
 
 # pylint: disable=protected-access
 _TRACE_SAMPLER = sampling._get_from_env_or_default()
@@ -533,7 +533,7 @@ class SpanLimits:
     - All limit arguments are optional.
     - If a limit argument is not set, the class will try to read its value from the corresponding
       environment variable.
-    - If the environment variable is not set, the default value for the limit is used.
+    - If the environment variable is not set, the default value, if any, will be used.
 
     Args:
         max_attributes: Maximum number of attributes that can be added to a Span.
@@ -609,15 +609,18 @@ def __repr__(self):
     def _from_env_if_absent(
         cls, value: Optional[int], env_var: str, default: Optional[int] = None
     ) -> Optional[int]:
-        if value is cls.UNSET:
+        if value == cls.UNSET:
             return None
 
         err_msg = "{0} must be a non-negative integer but got {}"
 
+        # if no value is provided for the limit, try to load it from env
         if value is None:
-            str_value = environ.get(env_var, "").strip().lower()
-            if not str_value:
+            # return default value if env var is not set
+            if env_var not in environ:
                 return default
+
+            str_value = environ.get(env_var, "").strip().lower()
             if str_value == _ENV_VALUE_UNSET:
                 return None
 


Test patch:
diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py
--- a/opentelemetry-sdk/tests/trace/test_trace.py
+++ b/opentelemetry-sdk/tests/trace/test_trace.py
@@ -1533,10 +1533,10 @@ def test_span_limits_code(self):
     @mock.patch.dict(
         "os.environ",
         {
-            OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: "unset",
-            OTEL_SPAN_EVENT_COUNT_LIMIT: "unset",
-            OTEL_SPAN_LINK_COUNT_LIMIT: "unset",
-            OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT: "unset",
+            OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: "",
+            OTEL_SPAN_EVENT_COUNT_LIMIT: "",
+            OTEL_SPAN_LINK_COUNT_LIMIT: "",
+            OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT: "",
         },
     )
     def test_span_no_limits_env(self):
Repository: open-telemetry/opentelemetry-python

Issue:
RuntimeError: Requested component 'jaeger' not found in entry points for 'opentelemetry_exporter'
From the exporters selection of [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#exporter-selection)

>Known values for OTEL_TRACES_EXPORTER are:
>
>- "otlp": OTLP
>- "jaeger": Jaeger gRPC
>- "zipkin": Zipkin (Defaults to protobuf format)
>- "none": No automatically configured exporter for traces.

We have split up the exporters based on protocol + serialisation to avoid taking unnecessary dependency so there is no entry point for `jaeger`. If someone reads the spec and follows that recommendation they will run into this error. We should either add an entry point `jaeger` or an alias that solves this problem.


Discussion:
Adding an alias could result in unexpected and hard to debug behavior as someone might expect gRPC and we enable thrift or vice-versa. I think we should do the following:

1. Update documentation to note actual exporter names (jaeger-thrift, jaeger-grpc, etc)
2. Handle cases like `jaeger` but crash early with a helpful error messaging guiding the user towards "jaeger-thrift", "jaeger-grpc" and may be a link to docs. 


What do you think about something like this? Update the glue package entry point with exporter default protocol recommended by spec.
```patch
diff --git exporter/opentelemetry-exporter-jaeger/setup.cfg exporter/opentelemetry-exporter-jaeger/setup.cfg
index b01b3a8d..7075ea14 100644
--- exporter/opentelemetry-exporter-jaeger/setup.cfg
+++ exporter/opentelemetry-exporter-jaeger/setup.cfg
@@ -44,3 +44,7 @@ install_requires =

 [options.extras_require]
 test =
+
+[options.entry_points]
+opentelemetry_exporter =
+    jaeger = opentelemetry.exporter.jaeger.proto.grpc:JaegerExporter
diff --git exporter/opentelemetry-exporter-zipkin/setup.cfg exporter/opentelemetry-exporter-zipkin/setup.cfg
index 6d2f9740..d3641e48 100644
--- exporter/opentelemetry-exporter-zipkin/setup.cfg
+++ exporter/opentelemetry-exporter-zipkin/setup.cfg
@@ -43,3 +43,7 @@ install_requires =

 [options.extras_require]
 test =
+
+[options.entry_points]
+opentelemetry_exporter =
+    zipkin = opentelemetry.exporter.zipkin.proto.http:ZipkinExporter
```
If there are defaults for jaeger,zipkin and otlp recommended by the spec then we should use them for sure. 

Resolving patch:
diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py
--- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py
@@ -109,7 +109,7 @@ def _import_exporters(
         exporter_name,
         exporter_impl,
     ) in _import_tracer_provider_config_components(
-        exporter_names, "opentelemetry_exporter"
+        exporter_names, "opentelemetry_traces_exporter"
     ):
         if issubclass(exporter_impl, SpanExporter):
             trace_exporters[exporter_name] = exporter_impl


Test patch:
Repository: open-telemetry/opentelemetry-python

Issue:
Do not count invalid attributes for dropped
https://github.com/open-telemetry/opentelemetry-python/blob/653207dd2181db1a766a4a703dcda78fd7703bb2/opentelemetry-api/src/opentelemetry/attributes/__init__.py#L175-L183

Existing attribute is deleted and new attribute is counted for dropped.  This should be fixed. Also we can use `.popitem()` which is optimised for deleting item on ends when we need to drop an attribute.


Discussion:

Resolving patch:
diff --git a/opentelemetry-api/src/opentelemetry/attributes/__init__.py b/opentelemetry-api/src/opentelemetry/attributes/__init__.py
--- a/opentelemetry-api/src/opentelemetry/attributes/__init__.py
+++ b/opentelemetry-api/src/opentelemetry/attributes/__init__.py
@@ -172,14 +172,16 @@ def __setitem__(self, key, value):
                 self.dropped += 1
                 return
 
-            if key in self._dict:
-                del self._dict[key]
-            elif self.maxlen is not None and len(self._dict) == self.maxlen:
-                del self._dict[next(iter(self._dict.keys()))]
-                self.dropped += 1
-
             value = _clean_attribute(key, value, self.max_value_len)
             if value is not None:
+                if key in self._dict:
+                    del self._dict[key]
+                elif (
+                    self.maxlen is not None and len(self._dict) == self.maxlen
+                ):
+                    self._dict.popitem(last=False)
+                    self.dropped += 1
+
                 self._dict[key] = value
 
     def __delitem__(self, key):


Test patch:
diff --git a/opentelemetry-api/tests/attributes/test_attributes.py b/opentelemetry-api/tests/attributes/test_attributes.py
--- a/opentelemetry-api/tests/attributes/test_attributes.py
+++ b/opentelemetry-api/tests/attributes/test_attributes.py
@@ -137,6 +137,9 @@ def test_bounded_dict(self):
 
         self.assertEqual(len(bdict), dic_len)
         self.assertEqual(bdict.dropped, dic_len)
+        # Invalid values shouldn't be considered for `dropped`
+        bdict["invalid-seq"] = [None, 1, "2"]
+        self.assertEqual(bdict.dropped, dic_len)
 
         # test that elements in the dict are the new ones
         for key in self.base: