class Ec2Resource extends ResourceProvider {

  @Override
  public Attributes getAttributes() {
    String token = fetchToken();

    // If token is empty, either IMDSv2 isn't enabled or an unexpected failure happened. We can
    // still get data if IMDSv1 is enabled.
    String identity = fetchIdentity(token);
    if (identity.isEmpty()) {
      // If no identity document, assume we are not actually running on EC2.
      return Attributes.empty();
    }

    String hostname = fetchHostname(token);

    Attributes.Builder attrBuilders = Attributes.newBuilder();
    attrBuilders.setAttribute(
        ResourceAttributes.CLOUD_PROVIDER, AwsResourceConstants.cloudProvider());

    try (JsonParser parser = JSON_FACTORY.createParser(identity)) {
      parser.nextToken();

      if (!parser.isExpectedStartObjectToken()) {
        throw new IOException("Invalid JSON:" + identity);
      }

      while (parser.nextToken() != JsonToken.END_OBJECT) {
        String value = parser.nextTextValue();
        switch (parser.getCurrentName()) {
          case "instanceId":
            attrBuilders.setAttribute(ResourceAttributes.HOST_ID, value);
            break;
          case "availabilityZone":
            attrBuilders.setAttribute(ResourceAttributes.CLOUD_ZONE, value);
            break;
          case "instanceType":
            attrBuilders.setAttribute(ResourceAttributes.HOST_TYPE, value);
            break;
          case "imageId":
            attrBuilders.setAttribute(ResourceAttributes.HOST_IMAGE_ID, value);
            break;
          case "accountId":
            attrBuilders.setAttribute(ResourceAttributes.CLOUD_ACCOUNT, value);
            break;
          case "region":
            attrBuilders.setAttribute(ResourceAttributes.CLOUD_REGION, value);
            break;
          default:
            parser.skipChildren();
        }
      }
    } catch (IOException e) {
      logger.log(Level.WARNING, "Could not parse identity document, resource not filled.", e);
      return Attributes.empty();
    }

    attrBuilders.setAttribute(ResourceAttributes.HOST_HOSTNAME, hostname);
    attrBuilders.setAttribute(ResourceAttributes.HOST_NAME, hostname);

    return attrBuilders.build();
  }

  public  Ec2Resource();
  @VisibleForTesting  Ec2Resource(String endpoint);

}