6464
6565import pkg_resources
6666
67- from opentelemetry .attributes import _filter_attributes
67+ from opentelemetry .attributes import (
68+ _create_immutable_attributes ,
69+ _filter_attributes ,
70+ )
6871from opentelemetry .sdk .environment_variables import (
6972 OTEL_RESOURCE_ATTRIBUTES ,
7073 OTEL_SERVICE_NAME ,
@@ -145,7 +148,7 @@ def __init__(
145148 self , attributes : Attributes , schema_url : typing .Optional [str ] = None
146149 ):
147150 _filter_attributes (attributes )
148- self ._attributes = attributes . copy ( )
151+ self ._attributes = _create_immutable_attributes ( attributes )
149152 if schema_url is None :
150153 schema_url = ""
151154 self ._schema_url = schema_url
@@ -187,7 +190,7 @@ def get_empty() -> "Resource":
187190
188191 @property
189192 def attributes (self ) -> Attributes :
190- return self ._attributes . copy ()
193+ return self ._attributes
191194
192195 @property
193196 def schema_url (self ) -> str :
@@ -210,7 +213,7 @@ def merge(self, other: "Resource") -> "Resource":
210213 Returns:
211214 The newly-created Resource.
212215 """
213- merged_attributes = self .attributes
216+ merged_attributes = self .attributes . copy ()
214217 merged_attributes .update (other .attributes )
215218
216219 if self .schema_url == "" :
@@ -239,7 +242,7 @@ def __eq__(self, other: object) -> bool:
239242
240243 def __hash__ (self ):
241244 return hash (
242- f"{ dumps (self ._attributes , sort_keys = True )} |{ self ._schema_url } "
245+ f"{ dumps (self ._attributes . copy () , sort_keys = True )} |{ self ._schema_url } "
243246 )
244247
245248
0 commit comments